-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to set version timestamp with sysdate from database
PostPosted: Thu Feb 26, 2004 12:59 pm 
Newbie

Joined: Thu Feb 26, 2004 12:45 pm
Posts: 2
Hi,
I anm using <version type='timestamp' column='lastMod' />
how could i set the lastMod column on insert and update with the time of my database server instead of the time of my appserver.

Thanks in advance
Thierry


Top
 Profile  
 
 Post subject: Re: How to set version timestamp with sysdate from database
PostPosted: Thu Feb 26, 2004 1:38 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Hi Thierry!

tahcow wrote:
how could i set the lastMod column on insert and update with the time of my database server instead of the time of my appserver.

I don't think it is a good idea to set version timestamp manually. As I got version is a utility field that is needed for optimistic locking and updating objects with composite-id. So let hibernate set it himself (it uses application server timestamp). As rule I use field access to all my versions and don't have setters for them for avoiding troubles.

If you need business timestamp field with database timestamp, introduce it and use SQL trigger or set it's default value to 'SYSTEM_DATE', 'CURRENT_TIMESTAMP' via SQL default clause of CREATE TABLE.


Top
 Profile  
 
 Post subject: Re: How to set version timestamp with sysdate from database
PostPosted: Thu Feb 26, 2004 2:58 pm 
Newbie

Joined: Thu Feb 26, 2004 12:45 pm
Posts: 2
The problem is when using a trigger on the database, the lastmod column value set by hibernate on update or insert is overwritten by the trigger which is executed after.
So the object become stale(if the time on both servers is not synchronize)
I know i can do a session.refresh(Object) after my update/save action but this is an extra select.

Thats why i want to find a way to tell hibernate to set the lastmod column value with the sysdate of the database. Can this be done ?

TIA
Thierry


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 4:15 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
version timestamp is an internal hibernate column/property, you should not change it either via trigger or manually. For business needs introduce another timestamp field and set it manually or via trigger, don't combine version timestamp and business timestamp property.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 11:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I would recommand version as an long usage.
getter / setter for version is needed in case of detach objects usage.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 3:46 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
I think public setter for version is not a good idea.
When I need to set version in some tricky cases I use factorty method or copy constructor with addition version parameter.
Code:
public MyCalss(MyClass that, int version)
{
    if (null == that)
        throw new NullPointerException();

    if (version <= that.version)
        throw new IllegalArgumentException();

    this.memeber1 = that.memeber1;
    ...
    this.version = version;
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can't do that with struts and it's JavaBean form

_________________
Emmanuel


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