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.  [ 3 posts ] 
Author Message
 Post subject: Exception while SessionImpl.list...could anyone help....
PostPosted: Fri Feb 19, 2010 7:58 pm 
Newbie

Joined: Fri Feb 19, 2010 7:47 pm
Posts: 2
I get following exception in my code intermittently. I cant find a definite pattern to reproduce this exception . Could someone please tell me how I can avoid this.

org.hibernate.AssertionFailure: possible non-threadsafe access to the session
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:100)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)


Top
 Profile  
 
 Post subject: Re: Exception while SessionImpl.list...could anyone help....
PostPosted: Mon Feb 22, 2010 9:52 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Code:
public static void initializeEntity(
         final Object entity,
         final boolean readOnly,
         final SessionImplementor session,
         final PreLoadEvent preLoadEvent,
         final PostLoadEvent postLoadEvent) throws HibernateException {
      
      ...
      final PersistenceContext persistenceContext = session.getPersistenceContext();
      EntityEntry entityEntry = persistenceContext.getEntry(entity);
      if ( entityEntry == null ) {
         throw new AssertionFailure( "possible non-threadsafe access to the session" );
      }


Looking at the implementation (code above) it seems that entityEntry == null in a place where it should never be null (if
working with an unique thread).
Therefore hibernate states that you probably are acceding the same session from another concurrent thread
and in this other thread you are removing entities from persistence context (for example by calling session.clear() or session.evict(entity) or session.close()).
You must check if in your application there are different thread sharing the same hibernate session,
that must be avoided.


Top
 Profile  
 
 Post subject: Re: Exception while SessionImpl.list...could anyone help....
PostPosted: Mon Feb 22, 2010 3:51 pm 
Newbie

Joined: Fri Feb 19, 2010 7:47 pm
Posts: 2
Hi...Thanks a lot...you pointed out the exact problem....one of the thread in my code was using the same session and clearing it.....so due to this race condition i was getting the exception intermitently.....i fixed the issue and haven't observed the exception so far....thank you again.....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.