-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate managed version
PostPosted: Wed Jul 28, 2004 2:04 am 
Beginner
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


Top
 Profile  
 
 Post subject: strange exception
PostPosted: Wed Jul 28, 2004 2:32 am 
Beginner
Beginner

Joined: Sun Mar 28, 2004 9:01 am
Posts: 21
... sorry for the posting, I solved the problem myself. It had nothing to do with the collections. I used the value object in a html form using BeanUtils.copyProperties. I only forgot to include the version number as hidden field in the jsp.

Therefor the version were not set in the Object when saveUpdate were called.

Sorry
Rene


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