-->
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.  [ 4 posts ] 
Author Message
 Post subject: New transaction fails after rollback
PostPosted: Wed Feb 06, 2008 10:18 am 
Newbie

Joined: Mon Jul 09, 2007 10:48 am
Posts: 7
Hibernate version: 3.2.4
I have problems with two transactions in one session.
The code:
Session session = Helper.currentSession();
for(int i=1;i<=3;++i) {
Transaction t2 = session.beginTransaction();
System.out.println("tran info "+t2.isActive()+"/"+t2.wasCommitted()+"/"+t2.wasRolledBack());
System.out.println("Inserting i: "+i);
try {
System.out.println("Transaction "+t2);
Smaz s = new Smaz(i);
session.save(s);
t2.commit();
} catch (Exception e) {
System.out.println("Error: "+e);
t2.rollback();
}
}
Helper.closeSession();

The Smaz(1) is inserted OK. For Smaz(2) is raised JDBC Error - OK. Smaz(3) should be inserted OK but the same JDCB error as for Smaz(2) is raised. The log is bellow.
The solution can be for each tran one session but I do not preffer this solution.
Please any idea how to solve it?

tran info true/false/false
Inserting i: 1
Transaction org.hibernate.transaction.JDBCTransaction@15d17d7
tran info true/false/false
Inserting i: 2
Transaction org.hibernate.transaction.JDBCTransaction@7eb366
2008-02-06 15:12:12,937 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Not possible to insert even number: 2
2008-02-06 15:12:12,937 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [hibernatepokus.Smaz]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at hibernatepokus.Main.testNestedTran(Main.java:50)
at hibernatepokus.Main.main(Main.java:63)
Caused by: com.sybase.jdbc2.jdbc.SybSQLException: Not possible to insert even number: 2
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2846)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:2168)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:220)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:203)
at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1702)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1685)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:115)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
... 12 more
Error: org.hibernate.exception.GenericJDBCException: could not insert: [hibernatepokus.Smaz]
tran info true/false/false
Inserting i: 3
Transaction org.hibernate.transaction.JDBCTransaction@e51b2c
2008-02-06 15:12:14,312 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Not possible to insert even number: 2
2008-02-06 15:12:14,312 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [hibernatepokus.Smaz]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at hibernatepokus.Main.testNestedTran(Main.java:50)
at hibernatepokus.Main.main(Main.java:63)
Caused by: com.sybase.jdbc2.jdbc.SybSQLException: Not possible to insert even number: 2
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2846)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:2168)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:220)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:203)
at com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1702)
at com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1685)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:115)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
... 12 more
Error: org.hibernate.exception.GenericJDBCException: could not insert: [hibernatepokus.Smaz]


Top
 Profile  
 
 Post subject: Re: New transaction fails after rollback
PostPosted: Wed Feb 06, 2008 11:24 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I read somewhere in HB document that a session object is not really good after it hits an exception. So, even if you can find a way to reuse a session in scope of multiple transaction may be you shouldn't since the first exception is going to wreck the whole thing.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 11:48 am 
Newbie

Joined: Mon Jul 09, 2007 10:48 am
Posts: 7
The question is if it is my bug or Hibernate bug?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 12:02 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
pernik1 wrote:
The question is if it is my bug or Hibernate bug?



I wouldn't say it is a bug, but it is a design decision. You will most likely need to change your code so that you fit into the HB model.



Farzad-


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