-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: batch insert
PostPosted: Mon May 02, 2005 3:45 am 
Beginner
Beginner

Joined: Tue Feb 15, 2005 8:14 am
Posts: 32
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.2

Mapping documents:

Code between sessionFactory.openSession() and session.close():
public void insertOrgUnits() {
ArrayList list = new ArrayList();

try {

for (int i = 0; i < 10000; i++) {

OrganisationUnitBean bean = new OrganisationUnitBean();
bean.setDescription("hej " + i);
bean.setName("name " + i);
bean.setNumber(new Integer(i));

OrganisationTypeBean organisationTypeBean = new OrganisationTypeBean();
organisationTypeBean.setId(new Long(1));
bean.setOrganisationType(organisationTypeBean);

bean.setShortName("shortname " + i);
list.add(bean);

}
insertOrgUnits2(list);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

private void insertOrgUnits2(ArrayList list) {

Session session = getSession();

Transaction tx = null;
try {
tx = session.beginTransaction();
Iterator iterator = list.iterator();
int i = 0;
while (iterator.hasNext()) {
i++;
OrganisationUnitBean bean = (OrganisationUnitBean) iterator.next();
Long id = (Long) session.save(bean);
if (i % 20 == 0) {
System.out.println("flush and clear");
session.flush();
session.clear();
}
System.out.println(" i : " + i + " saved : " + id);
}
tx.commit();
} catch (Exception e) {
System.out.println(e.getMessage());
try {
tx.rollback();
} catch (HibernateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} finally {
try {
session.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
}

I am trying to do a bacth insert like the documentation says, but the output when I execute the code is :

i : 1 saved : 74484
i : 2 saved : 74485
i : 3 saved : 74486
i : 4 saved : 74487
i : 5 saved : 74488
i : 6 saved : 74489
i : 7 saved : 74490
i : 8 saved : 74491
i : 9 saved : 74492
i : 10 saved : 74493
i : 11 saved : 74494
i : 12 saved : 74495
i : 13 saved : 74496
i : 14 saved : 74497
i : 15 saved : 74498
i : 16 saved : 74499
i : 17 saved : 74500
i : 18 saved : 74501
i : 19 saved : 74502
flush and clear

after this nothing happens.

What I am doing wrong here.


Top
 Profile  
 
 Post subject: java.lang.OutOfMemoryError
PostPosted: Mon May 02, 2005 3:47 am 
Beginner
Beginner

Joined: Tue Feb 15, 2005 8:14 am
Posts: 32
I can see that this result in an java.lang.OutOfMemoryError.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.