-->
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: hibernate session with exception and flush fails
PostPosted: Wed Aug 04, 2004 4:12 am 
Newbie

Joined: Wed Aug 04, 2004 3:50 am
Posts: 1
Hi,
i'm using hibernate 2.1.5. Together with the spring framework. (I'm using the hibernate interceptor).

I'm also using de OpenSessionInViewFilter (part of the spring framework). This opens a session for each request from the beginning till the end of the request.

When i'm doing something in my dao that throws a HibernateException (for example a unique key violation). Afterwards i can't flush my session anymore.

for example:
i'm inserting a user in the database. I'm inserting this user again, this throws a unique violation. Afterwards i'm trying to delete the first user and flush all this. I'm doing this within the same session (like the OpenSessionInViewFilter does).
The last flush fails during the following exception:
Code:
net.sf.hibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs)
   at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2641)
   at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2465)
   at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2458)
   at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2260)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
   at com.gudrun.test.dao.BaseDaoTestCase.tearDown(BaseDaoTestCase.java:58)
   at junit.framework.TestCase.runBare(TestCase.java:143)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:131)
   at junit.framework.TestSuite.runTest(TestSuite.java:173)
   at junit.framework.TestSuite.run(TestSuite.java:168)
   at junit.framework.TestSuite.runTest(TestSuite.java:173)
   at junit.framework.TestSuite.run(TestSuite.java:168)
   at junit.framework.TestSuite.runTest(TestSuite.java:173)
   at junit.framework.TestSuite.run(TestSuite.java:168)
   at junit.framework.TestSuite.runTest(TestSuite.java:173)
   at junit.framework.TestSuite.run(TestSuite.java:168)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)



Is this normal behaviour?
If you want to do some code that can throw an exception, do you have to start every time a new session for such code, because this can be very heavy.

thanks in advance,
Jan Verhulst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 4:51 am 
Beginner
Beginner

Joined: Wed Aug 04, 2004 4:33 am
Posts: 45
Location: Switzerland
i think if you get an exception you should close the session and open a new one.


Top
 Profile  
 
 Post subject: Session Problem, maybe?????
PostPosted: Tue Oct 12, 2004 6:45 am 
Newbie

Joined: Tue Oct 12, 2004 6:28 am
Posts: 6
I am facing a similar problem but instead of calling the former I am performing adding and deleting persistent objects with collections on different sessions. Usually this works fine but sometimes I get an integrity constraint that the referenced object is not found (i.e. In my case I am using the example Cat and Claws). The problem began when I started using collections with my classes.

Is this an issue with Session or am I doing something wrong with my mapping. Even though it works fine in some cases.


Top
 Profile  
 
 Post subject: HibernateExceptions are unrecoverable
PostPosted: Tue Oct 12, 2004 11:54 am 
Newbie

Joined: Fri Oct 08, 2004 11:59 am
Posts: 16
Location: Helsinki, Finland
Gavin King says:
Quote:
as per the documentation, no HibernateException is recoverable.

in:
http://opensource.atlassian.com/projects/hibernate/browse/HB-1186

Quote:
If you want to do some code that can throw an exception, do you have to start every time a new session for such code, because this can be very heavy.


So, you don't have to start a new session for all exceptions, only for HibernateExceptions. If you get a HibernateException, your session is no more usable, but if it's some other exception, that should not affect the session.

- Ville Peurala


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.