-->
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.  [ 9 posts ] 
Author Message
 Post subject: How do I not update version field if no fields are changed?
PostPosted: Tue Sep 12, 2006 5:43 am 
Beginner
Beginner

Joined: Tue Mar 21, 2006 5:49 pm
Posts: 20
When I call saveOrUpdate, then the version field is updated even if no other fields have changed... Is there anyway to tell Hibernate not to update the version field as long as no changes have been made?


Regards,

BTJ

_________________
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 3:07 pm 
Beginner
Beginner

Joined: Tue Mar 21, 2006 5:49 pm
Posts: 20
This isn't possible?? Shouldn't it be?

BTJ

_________________
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"


Top
 Profile  
 
 Post subject: Same problem...
PostPosted: Wed Sep 27, 2006 4:43 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:55 pm
Posts: 37
Hi

I seem to experience something similar...

My stateless session EJB returns a Hibernate object just selected from the DB (no direct call to save or saveOrUpdate), just select via HQL.

When it returns, it commits the txn that was started on hitting the EJB AND it updates the version number and ONLY the version number.

This seems to break the optimistic concurrency contract...

has anyone experienced this with 3.1.3?
What am I doing wrong?

Thanks

Benoit


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 4:15 pm 
Newbie

Joined: Wed Apr 19, 2006 12:50 pm
Posts: 8
i am experiencing the same problem and is very interested if someone can explain why this is happening..??

thanks

Rasmus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 5:22 pm 
Beginner
Beginner

Joined: Tue Aug 29, 2006 8:13 pm
Posts: 32
Location: Spain (GU)
Hi,

I found the same problem when I was particularly interested in Hibernate performance. The solution is really easy (even I solved it) :-)

There is a property in tag class. I paste the content of Hibernate manual:


You may declare a persistent class using the class element:

Code:
<class
        name="ClassName"                              (1)
        table="tableName"                             (2)
        discriminator-value="discriminator_value"     (3)
        mutable="true|false"                          (4)
        schema="owner"                                (5)
        proxy="ProxyInterface"                        (6)
        dynamic-update="true|false"                   (7)
        dynamic-insert="true|false"                   (8)
        select-before-update="true|false"             (9)
        polymorphism="implicit|explicit"              (10)
        where="arbitrary sql where condition"         (11)
        persister="PersisterClass"                    (12)
        batch-size="N"                                (13)
        optimistic-lock="none|version|dirty|all"      (14)
        lazy="true|false"                             (15)
/>


(7) dynamic-update (optional, defaults to false): Specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed.

(8) dynamic-insert (optional, defaults to false): Specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.

Best regards.

_________________
Please don't forget the credit system.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 9:52 am 
Newbie

Joined: Wed Apr 19, 2006 12:50 pm
Posts: 8
thanks for your reply javier..!
dynamic update didnt solve my problem unfortunately - the version column was still being updated when commiting the transaction with only read queries. The problem is as far as i can tell that the queried objects for some reason become dirty and therefore will be updated on commit despite haven't modified them.
I solved the problem with a session.clear() before commit - however i am not sure it is the best solution. I would like to avoid the objects from being dirty in the first place. any idea..?

sorry if this is a trivial question..

best regards
Rasmus


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 10:03 am 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
rasmusk wrote:
thanks for your reply javier..!
dynamic update didnt solve my problem unfortunately - the version column was still being updated when commiting the transaction with only read queries. The problem is as far as i can tell that the queried objects for some reason become dirty and therefore will be updated on commit despite haven't modified them.
I solved the problem with a session.clear() before commit - however i am not sure it is the best solution. I would like to avoid the objects from being dirty in the first place. any idea..?

sorry if this is a trivial question..

best regards
Rasmus

I cant imagine why hibernate thinks your object is "dirty"

I can suggest the following option

1. Tell hibernate not to dirty check the object by setting read only

Quote:
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html#setReadOnly(java.lang.Object, boolean)


2. set the flush mode to manual

3. Implemetn your own dirty checking for that object in an interceptor...

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 04, 2007 12:46 pm 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
can you post your EJB code using Hibernate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 1:26 pm 
Newbie

Joined: Wed Apr 19, 2006 12:50 pm
Posts: 8
here is the code that returns true when checking for dirty.. (it works fine if i query another table)


String queryString2 = "from Customer";
List list2 = session.createQuery(queryString2).list();


and the corresponding hbm:

<hibernate-mapping>
<class name="model.Customer" table="customer" lazy="false">
<id name="customerId" column="customer_id" type="integer">
<generator class="sequence">
<param name="sequence">customer_sequence</param>
</generator>

</id>
<version name="version" column="version"/>
<property name="firstname" column="firstname" type="string" />
<property name="lastname" column="lastname" type="string" />
<property name="street" column="street" type="string" />
<property name="postalCode" column="postal_code" type="string" />
<property name="city" column="city" type="string"/>
<property name="email" column="email" type="string"/>



<set name="bookings" inverse="true">
<key column="booking_id"/>
<one-to-many class="model.Booking"/>
</set>


</class>
</hibernate-mapping>


thanks
rasmus


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