-->
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: Possible non threadsafe exception ??
PostPosted: Mon Mar 21, 2005 8:22 am 
Beginner
Beginner

Joined: Wed Feb 04, 2004 5:21 pm
Posts: 37
After making a few changes to my otherwise solid framework, I got the following exception running my automated tests

possible nonthreadsafe access to session

net.sf.hibernate.AssertionFailure: possible nonthreadsafe access to session at net.sf.hibernate.impl.SessionImpl.postInsert(SessionImpl.java:2406) at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:38) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2391) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260) at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61) at com.bluprinted.personal.account.AccountMonitor.updatePhoneManufacturerTable(AccountMonitor.java:192) at com.bluprinted.personal.test.WurflTestCase.testAddPhoneModels(WurflTestCase.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)


Hibernate 2
MySQL 4.1.10
MySQL connector/j 3.1.7


The code that fails:

Session session = contentDatabase.getCurrentSession();
trx = session.beginTransaction();
Iterator brandItr = brandList.iterator();
while(brandItr.hasNext()) {
caption = ((String)brandItr.next());
if (caption.length()>50) caption = caption.substring(0,50);
String name = caption.toUpperCase();
Object pm = session.get(PhoneManufacturer.class,name);
if (pm==null) {
buf.append(caption);
if (brandItr.hasNext()) buf.append(", ");
PhoneManufacturer manu = new PhoneManufacturer();
manu.setName(name);
manu.setCaption(caption);
session.save(manu);
}
else
session.evict(pm);
}
trx.commit();
contentDatabase.getSessionFactory().evict(PhoneManufacturer.class);


The failure happens in the commit. Is it the evict that ruins the show ?

Henrik


Top
 Profile  
 
 Post subject: solution
PostPosted: Mon Mar 21, 2005 8:55 am 
Beginner
Beginner

Joined: Wed Feb 04, 2004 5:21 pm
Posts: 37
Apparently evict wasn't the right way to go about it.

I replaced the session.evict(pm) with the following after reading a blog on batch processing (http://blog.hibernate.org/cgi-bin/blosx ... batch.html)

++count;
if ( count % 20 == 0 ) {
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}


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.