After reading the hibernate reference, you can use batch processing, when the inserted data exceeds 10000, flush session and clear.
Here is a test method.
1/**//**
2 * Test Batch Insert data transaction, return succeeded
3 *
4 * @param objpo Object
5 * @return BOOLEAN
6 */
7 public boolean insertbatch (final Object objpo) {
8 Boolean issuccess = false;
9 Tr Ansaction transaction = NULL;
Sessions session = Opensession ();
One try {
transaction = Session.begintransaction ();
for int i = 0; i < 100000 ; i + +) {
Session.save (OBJPO);
if (i% = 0) {
//flush a batch of Inserts and release memory
Session.flush ();
Session.clear ();
}
20
Transaction.commit ();
Logger.info ("transaction.wascommitted:"
+ transaction.wascommitted ());
Issuccess = true;
Hibernateexception ex) {
(transaction!= null) {
try {
28 TraNsaction.rollback ();
Logger.error ("Transaction.wasrolledback:"
+ transaction.wasrolledback ());
To catch (Hibernateexception Ex1) {
Logger.error (ex1.getmessage ());
Ex1.prin Tstacktrace ();
34}
35}
Logger.error ("Insert Batch PO Error:" + ex.getmessage ());
Notoginseng ex.printstacktrace ();
-} finally {
41-if (transaction!= null) {
transaction = null;
:}< br> Session.close ();
43}
return issuccess;
45}