-->
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.  [ 5 posts ] 
Author Message
 Post subject: <joined-subclass> with <timestamp> fails for Ora
PostPosted: Thu Nov 18, 2004 12:03 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 1:29 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Have you changed your Dialect in your hibernate properties?

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 18, 2004 3:12 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
yes


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 6:31 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oracle driver bug.


Top
 Profile  
 
 Post subject: Oracle 8.1.7 dbs get a corrupt numeric field after a date
PostPosted: Fri Apr 21, 2006 1:27 am 
Newbie

Joined: Fri Apr 21, 2006 1:10 am
Posts: 1
This a breakdown of the problem that we found developing against our legacy Oracle 8.1.7 database:

Hibernate 2.1.5
Oracle database 8.1.7
Oracle JDBC driver 9.2.0.1, 10.2.0.1.0 (and probably many others)

When a table includes a Date column the next numeric field after the date got corrupted doing a Hibernate save. The corruption caused the numeric field to hold bizarre float values, even if the column was declared without precision - e.g number (10) - which I would have expected to cause a db error. Changing the order of field mappings in the *hbm.xml file changed the field which was corrupted - always the next numeric after the date.

The error did not occur with Oracle 9* databases - it is a problem with the communication of values from the driver to the database, not just with the driver. To restate; the database appears to be at fault, not the driver.

Changing the object mapping from type="java.util.Date" to type="time" seems to fix the problem - I found this solution at (the end of) http://forum.hibernate.org/viewtopic.php?t=932564&highlight=date+time.

_________________
Will


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.