Q:

javax.persistence.TransactionRequiredException while performing inserts in a loop

I have an application which uses Spring, Hibernate and JTA.
We received a request with larger than expected data (10000 elements), general requests are 10-100 elements.
While processing this request we try to insert a record in DB for each of these elements and that's done in a for loop
pseudo code:
processRecords( list){

for (Element element: list){

dao.findBy -- This takes around 100 ms

-- some other checks and logic

dao.add(element); -- This takes around 150 ms
dao.flush();
 }

}

This block takes a lot of time to process the records and then I get *

"javax.persistence.TransactionRequiredException: no transaction is in
  progress"

*
I tried moving the flush out of the for loop, did not help, I tried researching on batch inserts for hibernate , but this is a huge application with lots of customization and I do not see that as an option as it will impact whole application, Also I tried finding where is the Transaction duration configured and only place I could find was in JTA on weblogic and it was set to 480 Sec.
Any indicators on how to solve this scenario would be much appreciated.
Edit:
increasing the JTA Timeout in weblogic has solved the problem temporarily, but I set it to a very large value 5000 sec, is there anyway to improve the performance, since I am just inserting 8K records (I know batch processing is one option, but there are some constraint in custom "framework" around that)

A:

Use @Transactional to control the transactions. 

Make sure to not automatically start a transaction with PROPAGATION_NEVER
Start new transactions for each item in list (or subset of items in list) by calling a service method with REQUIRES_NEW. 

In the second step, you might want to call on another bean so that the transaction annotation is actually picked up, can't remember whether this works on methods on the same object.

