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.  [ 6 posts ] 
Author Message
 Post subject: Managed versioning doesn't work as expected
PostPosted: Tue Aug 16, 2005 9:10 am 
Newbie

Joined: Tue Aug 16, 2005 8:15 am
Posts: 3
Location: Vienna
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>

<class
    name="m04.bo.ZdAdresse"
    table="ADRESSEN"
>

    <id
        name="id"
        type="java.lang.Long"
        column="ID"
    >
        <generator class="sequence">
                <param name="sequence">ADR_SEQ</param>
        </generator>
    </id>
   
    <version
        name="version"
        type="java.lang.Long"
        column="VERSION"       
    />
   
    <property
        name="strasse"
        type="java.lang.String"
        column="STRASSE"
        not-null="true"
        unique="true"
        length="36"
    />
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
ZdAdresseDAO adrDAO = new ZdAdresseDAO();   
ZdAdresse adrBO = adrDAO.read(new Long(3));       

adrBO.setStrasse("Str");
adrBO.setVersion(new Long(777)); // version database: 775
adrDAO.update(adrBO);   



Name and version of the database you are using: Oracle 8i

Hi!

In our project we want to use managed versioning, but it seems that Hibernate doesn't recognizes a missmatch between the version-field in the database and the version in our local modified object.

We expect a StaleObjectStateException to be thrown but the database-record is updated without exception.

Thx in advance
Christian


Top
 Profile  
 
 Post subject: version
PostPosted: Tue Aug 16, 2005 12:17 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
If I recall correctly H check version on attaching previously detached object to the current session, it does not check what is in DB.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:59 am 
Newbie

Joined: Tue Aug 16, 2005 8:15 am
Posts: 3
Location: Vienna
Hy,
we are loading an object into the session, updating some values including version attribute, and commtting it (container managed transaction) in a Stateless Session Bean
We tried it without calling dao.update too, because Hibernate checks if an object is dirty and persists it automatically into the DB. But the version check faild in both ways.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 7:32 am 
Newbie

Joined: Tue Aug 16, 2005 8:15 am
Posts: 3
Location: Vienna
Hi!

Our problem still exists and we weren't able to fix it until now.

Is there nobody out there who can help us ???


Top
 Profile  
 
 Post subject: do not set version explicitly
PostPosted: Wed Aug 24, 2005 11:20 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
This is the test code that works and I hope simulated your situation
// lets make sure we have object in DB
s = currentSession();
if( s.createQuery("from ZdAdresse t where t.id = 1").uniqueResult() == null){
s.save( new ZdAdresse( new Long( 1 ), "someName"));
}
closeSession();

//this probably simulates situation when user gets object in first request
s = currentSession();
ZdAdresse v = (ZdAdresse) s.get(ZdAdresse.class, new Long( 1 ));
System.out.println("from ZdAdresse = " + v );

closeSession();
//this modification happens outside of Hibernate session
v.setStrasse( "Strasse:" + System.currentTimeMillis());

//now we get session and reattach object
s = currentSession();
s.merge( v );
closeSession();

//Not the object gets updated in the database

Please note - nowhere in the code we set version property of the object, Hibernate manages it.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 24, 2005 1:17 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
panda wrote:
Hy,
we are loading an object into the session, updating some values including version attribute, and commtting it (container managed transaction) in a Stateless Session Bean
We tried it without calling dao.update too, because Hibernate checks if an object is dirty and persists it automatically into the DB. But the version check faild in both ways.


Why are you changing the version attribute in your code ? You shouldn;t be touching this. Hibernate decides on whether to change this or not by ( I think) introspecting or using CGLIB to detect changes between the the database and local copy of the data.

A guaranteed way of you resolving your problem is just to step through the hibernate code using your debugger. I had the same problem (sorry I have no memory of what caused it) but it was easy enough to fix in debug.

_________________
On the information super B road


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