Hi All
I've a class B and a subclass SubB. They are maped with a joined-subclass mapping. B is versioned with a timestamp.
For MySql everything works fine. If I do the very same thing for Oracle 8.1.7 I get a StaleObjectStateException, because an update to the B table fails.
Even more strange: I log the SQL statements with p6spy. If I execute them manually everything seams to work fine, the update returns 1 row processed.
Without the <timestamp> everything works fine.
Any ideas?
TIA
Ernst
Hibernate version:
2.1.6
Mapping documents:
Code:
hibernate-mapping>
<class name="ch.bedag.playground.B" table="B">
<id name="idb" access="field">
<column name="idb" not-null="true"/>
<generator class="increment"/>
</id>
<timestamp name="myTimestamp" column="timestamp" access="field"/>
<property name="myBeschreibung" column="beschreibung" access="field"/>
<many-to-one name="a" column="a_id" access="field" />
</class>
<joined-subclass name="ch.bedag.playground.SubB" extends="ch.bedag.playground.B">
<key column="idsubb" />
<property name="myText" column="text" access="field"></property>
</joined-subclass>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Session s = HibernateUtil.getSession();
HibernateUtil.beginTransaction();
SubB sb = new SubB();
s.save(sb);
sb.setBeschreibung("SubB");
sb.setText("SubB Text");
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
Full stack trace of any exception that occurs:Code:
Opening new Session for this thread.
Starting new database transaction in this thread.
Committing database transaction of this thread.
Hibernate: insert into B (timestamp, beschreibung, a_id, idb) values (?, ?, ?, ?)
Hibernate: insert into SubB (text, idsubb) values (?, ?)
Hibernate: update B set timestamp=?, beschreibung=?, a_id=? where idb=? and timestamp=?
Hibernate: update SubB set text=? where idsubb=?
16:48:15,214 WARN StaleObjectStateException:27 - 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 ch.bedag.playground.SubB instance with identifier: 1
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:511)
at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:691)
at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:666)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2437)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2391)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2259)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at ch.bedag.playground.HibernateUtil.commitTransaction(HibernateUtil.java:182)
at ch.bedag.playground.SubBTest.testSubB(SubBTest.java:32)
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.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 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)
16:48:15,214 ERROR SessionImpl:2398 - Could not synchronize database state with session
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for ch.bedag.playground.SubB instance with identifier: 1
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:511)
at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:691)
at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:666)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2437)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2391)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2259)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at ch.bedag.playground.HibernateUtil.commitTransaction(HibernateUtil.java:182)
at ch.bedag.playground.SubBTest.testSubB(SubBTest.java:32)
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.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 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)
Tyring to rollback database transaction of this thread.
Closing Session of this thread.
Name and version of the database you are using:Oracle 8.1.7
The generated SQL (show_sql=true):DML:
Code:
Hibernate: insert into B (timestamp, beschreibung, a_id, idb) values (?, ?, ?, ?)
Hibernate: insert into SubB (text, idsubb) values (?, ?)
Hibernate: update B set timestamp=?, beschreibung=?, a_id=? where idb=? and timestamp=?
Hibernate: update SubB set text=? where idsubb=?
DDL:
Code:
alter table C drop constraint FK43196A8
alter table SubB drop constraint FK277E22B8E411BD
alter table B drop constraint FK422D89B9
drop table A cascade constraints
drop table C cascade constraints
drop table SubB cascade constraints
drop table B cascade constraints
create table A (
ida number(10,0) not null,
timestamp date not null,
beschreibung varchar2(255),
primary key (ida)
)
create table C (
idc number(10,0) not null,
myName varchar2(255),
primary key (idc)
)
create table SubB (
idsubb number(10,0) not null,
text varchar2(255),
primary key (idsubb)
)
create table B (
idb number(10,0) not null,
timestamp date not null,
beschreibung varchar2(255),
a_id number(10,0),
primary key (idb)
)
alter table C add constraint FK43196A8 foreign key (idc) references A
alter table SubB add constraint FK277E22B8E411BD foreign key (idsubb) references B
alter table B add constraint FK422D89B9 foreign key (a_id) references A