|
Hi,
I got the following 'StaleObjectStateException' exception if I use the "assigned" generator.
I use the "assigned" generator as my ID like here:
<id name="name" type="string" column="USER_ID"
unsaved-value="null" access="profiling.DirectSetAccessor">
<generator class="assigned" />
</id>
but if I create a seperate id attribute in my user class and use the "native" geneartor, it works.
<id name="id" type="long" column="USER_AGENT_ID"
unsaved-value="null" access="profiling.DirectSetAccessor">
<generator class="native" />
</id>
And can someone please tell me what is the recommend practice in hibernate? create a separate ID field in the User class or use the unqiue identifier in the User class as the primary key (e.g. userID) of the database?
In the examples of the "Hibernate in Action" book, it uses a separate ID field, I am not sure I understand why?
Thank you for any help.
10:04:03,505 WARN StaleObjectStateException: An operation failed due to stale data
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for profiling.model.UserAgent instance with identifier: userAgent1
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:513)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:664)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:621)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2393)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at profiling.HibernateUtil.commitTransaction(HibernateUtil.java:173)
at junit.UserAgentTest.testCreateUser3(UserAgentTest.java:174)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.TestCase.runTest(TestCase.java:17)
at junit.framework.TestCase.runBare(TestCase.java:127)
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:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
|