-->
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.  [ 4 posts ] 
Author Message
 Post subject: Utilize NOW() in an update?
PostPosted: Thu Dec 11, 2003 4:55 pm 
Newbie

Joined: Thu Nov 27, 2003 5:27 pm
Posts: 10
Using MySQL and Hibernate, what would be the preferred way to update a column to NOW(), so that I get the time on the database server, not the application server? Do I have to write my own SQL update statement, or is there another way to have Hibernate pass NOW() along as the value to use?

Thanks,
Lee Grey

_________________
http://www.URLinOne.com
http://www.AuctionRelay.com
http://www.OptionInsight.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 5:02 pm 
Newbie

Joined: Thu Nov 27, 2003 5:27 pm
Posts: 10
I guess a little more detail couldn't hurt.

I'm trying to mark an open session as closed by putting the current timestamp into the "closed" column. I don't think there's anything that I can put into the UserSession object's closed property that would cause the database to put the value from NOW() into it.

What other alternatives do I have?

Thanks,
Lee

_________________
http://www.URLinOne.com
http://www.AuctionRelay.com
http://www.OptionInsight.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) use new Date()
(2) use direct JDBC or a custom persister


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 11, 2003 7:17 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 4:54 pm
Posts: 26
Location: Chicago, IL
Along the lines of a customer persister approach, you could define a utility class that periodically queries the actual database for the current timestamp.

If you are willing to sacrifice some accuracy for performance, you can set this class up so that it only periodically queries the database and stores a "drift" value from the current system clock. (You lose the nanosecond precision of database timestamps because System.currentTimeMillis() doesn't support nanoseconds, plus you lose the accuracy of your own system clocks drift in between polling intervals.)

Some sample SQL to query the current timestamp for DB2 would be:

SELECT CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY

I'm not sure offhand what the SQL for MySQL would be, but it should be similar (you might need to setup a "dummy" table with a single row to make this work).


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