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: How can I update a field in the DB with the DB's sys time?
PostPosted: Thu Mar 16, 2006 7:39 pm 
Newbie

Joined: Thu Mar 16, 2006 1:12 pm
Posts: 10
All,

I have a non-hibernate application that I'm trying to port to hibernate 3.0. Currently, the non-hibernate application does things like this:

update clientTable set lastHeartBeat=sysdate where id=35;

In the above example, "sysdate" is particular to Oracle and represents the current time. I like using the system time because we are running in a clustered environment and our application servers could conceivably have different times on them - hence we use the databases's time. Doing it this way, I also don't need to READ the sysdate from the DB *before* making the above call.

I'd be interested to know if I could do something like this in hibernate?

Thanks,

-john


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 10:07 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You could use triggers, but the timestamp datatype would be better. If you change the type of you column to timestamp (I presume it's datetime at the moment) then Oracle will update it automatically whenever you update the row, whether you use hibernate or not. Hibernate has full support for the timestamp SQL type: just map the property with insert="false" update="false" to ensure that the value is only ever updated by the server (timestamp columns may be overwritten by user-provided values).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 8:03 am 
Newbie

Joined: Mon Apr 03, 2006 7:14 am
Posts: 2
tenwit wrote:
If you change the type of you column to timestamp (I presume it's datetime at the moment) then Oracle will update it automatically whenever you update the row, whether you use hibernate or not.


this doesn't work for me. are you getting confused with the MySql timestamp type ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 5:48 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I'm not getting confused with MySQL, as I've never used that. However it might be that timestamp on SQLServer is different from timestamp on whatever DBMS you're using.

Note that I mean the SQL column type should be timestamp: setting the column type to timestamp in your mapping isn't enough, you must do it in the DB.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 4:35 am 
Newbie

Joined: Mon Apr 03, 2006 7:14 am
Posts: 2
well, i'm using Oracle as discussed in the original post and i have set the db column to timestamp using the sql-type attribute of <column> and it is the right type in the db but i can't get Oracle to update that column automatically. i just thought i might be missing a trick here.

maybe the <sql-update> element might another way to achieve the required functionality though there is an argument that it defeats the purpose of using an ORM.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 5:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You could read up on the <version> tag, maybe it'll do what you need?


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.