-->
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: queries inside events - why it doesn't work?
PostPosted: Tue Mar 07, 2006 11:27 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
I try to use the events to check the database consistency (business rules).
Scenario:
- save object of type A
- preInsert event called - here I do query on currentSession
- save object of type A (but different than before).

Quote:
This gives exception:
aused by: org.hibernate.exception.GenericJDBCException: could not insert:
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:59)
at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1473)
at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1092)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:306)
... 63 more




Caused by: java.sql.SQLException: Connection handle has been closed and is unusable
at org.jboss.resource.adapter.jdbc.WrappedConnection.checkStatus(WrappedConnection.java:526)
at org.jboss.resource.adapter.jdbc.WrappedConnection.checkTransaction(WrappedConnection.java:513)
at org.jboss.resource.adapter.jdbc.WrappedStatement.checkTransaction(WrappedStatement.java:537)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:223)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
... 76 more


I tried to debug a little bit, and foound out that it could be similar to the post:
http://forum.hibernate.org/viewtopic.ph ... ht=batcher

Hibernate Version: 3.1.2
Any workaround? Or is it a bug?


Last edited by tbech on Wed Mar 08, 2006 5:50 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 2:58 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
To be more precise:
I use the 'preInsert' event to do some queries on the DB (in the same session - it is a must, becuase of the logic of the application).
Problem is that the query causes closing of connection which are supposed to be allocated for 'insert'.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 5:46 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
We've dig out more about events and we suspect the worst possible :(
1. You cannot use query in preInsert - reaction as above.
2. What anyone would expect from postInsert event?
That the record is already inserted in DB. No, not in Hibernate. Due to using of batcher and other stuff, the records are inserted/updated/deleted during flush (which comes at the end).
Exception: if two batches in the transaction (the first will be saved during prepareStatement in prepareBatchStatement, second during flush. Why so?


So what is the real usage pattern for event. We have choosen hibernate to achive two things by using events:
- to have preInsert/postInsert to do there some validation check (business rules);
- to do in postInsert/delete/update crateation of historical data in special historical tables.

So, are events designed for such requirement (simple one in fact: allow other queries during events)? And how to achieve this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 3:19 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
The patch is in http://opensource.atlassian.com/project ... e/HHH-1578.
Unfortunately the anomaly is wrongly rejected.


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.