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.  [ 1 post ] 
Author Message
 Post subject: How can exceptions in one session, disturb another session?
PostPosted: Tue May 03, 2011 11:25 am 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hi,

I am puzzled by a quite strange behaviour. We have two threads, both with their own sessions (and only integer-id's are passed between threads).
However when one thread triggers a ConstraintViolationException because it tries to persist invalid entities, the other thread starts to become non-functional too
and it throws the following Exception:

Code:
org.hibernate.exception.GenericJDBCException: could not load an entity: [somepackage.SomeClass#397]
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1957)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:69)
   at org.hibernate.loader.entity.BatchingEntityLoader.load(BatchingEntityLoader.java:113)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3270)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1080)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:997)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:990)
   at khdb.kladde.AsyncStatusCalculator.run(AsyncStatusCalculator.java:98)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
   at java.lang.Thread.run(Thread.java:662)

  //The current transaction has been aborted, commands are ignored till exception is ended.
Caused by: org.postgresql.util.PSQLException: FEHLER: aktuelle Transaktion wurde abgebrochen, Befehle werden bis zum Ende der Transaktion ignoriert
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1869)
   at org.hibernate.loader.Loader.doQuery(Loader.java:718)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1953)
   ... 17 more


The code looks like this:
Code:
//Thread one
try {
  tx.begin();
  session.persist();  //Will lead to: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
  tx.commit();
}catch(Exception e) {
  tx.rollback();
}


//Thread two:
public void run() {
  Session session = sessionFactory.openSession;
  try {
        session.get(SomeClass.class, id); //Throws an exception
  }finally {
        session.close();
   }
}


Any idea whats going wrong here? How can one session interfer with a completly seperated one?

Thank you in advance, Clemens


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

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.