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