Beginner |
|
Joined: Sun Mar 28, 2004 9:01 am Posts: 21
|
Hello I wanted to use the optimistic lock strategie bundled with hibernate. Therefor I added a version tag to all persisted objects (I did that in an Abstract Class from where all other classes are derived).
Hibernate Version: 2.1.4
Database: Oracle 9i
/**
* @return
* @hibernate.version
* column = "VERSION"
*/
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
<hibernate-mapping>
<class name="at.sozvers.eko.model.Produkt" table="MEPR" dynamic-update="false" dynamic-insert="false">
<id name="id" column="id" type="java.lang.Long" unsaved-value="null">
<generator class="net.sf.hibernate.id.SequenceGenerator">
<param name="sequence">hibernate_sequence</param>
</generator>
</id>
<version name="version" type="java.lang.Long" column="VERSION" access="property" unsaved-value="undefined"/>
...
</hibernate-mapping>
Within the database I added a column to every Table:
CREATE TABLE xxx (
...
VERSION numeric
);
My first question is wheter I can use the numeric datatype for the version attribute and map that value to a Long? Or do I need to use an int value?
My second question is, why I get an exception during saveUpdate when adding the version tag to the Abstract Class:
Java code between openSession and close:
Transaction tx = session.beginTransaction();
session.saveOrUpdate(object);
tx.commit();
Stacktrace:
Caused by: net.sf.hibernate.HibernateException: You may not change the reference to a collection with cascade="all-delete-orphan"
at net.sf.hibernate.impl.SessionImpl.prepareCollectionForUpdate(SessionImpl.java:2949)
at net.sf.hibernate.impl.SessionImpl.updateReachableCollection(SessionImpl.java:2886)
at net.sf.hibernate.impl.FlushVisitor.processCollection(FlushVisitor.java:32)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.AbstractVisitor.processValues(AbstractVisitor.java:36)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2588)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2454)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2256)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2235)
at net.sf.hibernate.transaction.JTATransaction.commit(JTATransaction.java:52)
at at.sozvers.eko.persistence.HibernateManager.saveOrUpdate(HibernateManager.java:85)
When removing the version tag everything works fine? Any idea?
Thx Rene
|
|