Reputation: 69
, Iam working on this project in hibernate, where the user enters the quantity based on this number i need to display the unique fields in the next form (For example if the user enters quantity as 5 then 5 MAC Address and DeviceSerial fields are shown in the jsp page, the other common information about the devices are entered in the same form where quantity is entered) and all this information should be put into the database . Thanks!
Upvotes: 0
Views: 451
Reputation: 7836
You should go for Batch Insert in hibernate.
Batch Insertion is a powerful feature of hibernate particularly useful when you are importing data from other systems in batch. If you do not use batch feature of hibernate, your application's performance may decrease dramatically at the time of insertion of many records.
For more information visit hibernate tutorials.
Upvotes: 1
Reputation: 2332
Please take a look at this page: webpage
You should open a transaction, save all entities (in loop), at the end commit the transaction and close the session. You should not commit for every single record but at the end.
Referenced to Goran or
if you can use hibernateTemplate instead of session then you can save your object list by using saveOrUpdateAll(Collection entities).
Although HibernateTemplate saveOrUpdateAll does save a collection at once but, it will use the same loop logic of saving the object and flushing
Upvotes: 1