-->
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.  [ 8 posts ] 
Author Message
 Post subject: Updating a column with current timestamp
PostPosted: Mon Dec 05, 2005 9:56 pm 
Newbie

Joined: Mon Dec 05, 2005 9:48 pm
Posts: 3
I want to set a column with current timestamp of database server whenever I update an object.

I do not want to set it to web server timestamp where my hibernate code is running. Also, I do not want use the database triggers for this operation.

Is there any way to do it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 8:51 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
If NHibernate is running on the web server, I don't know how it can use the datetime of the database server. So you probably have to do this yourself...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 10:23 am 
Newbie

Joined: Tue Nov 01, 2005 6:32 pm
Posts: 16
Why do the servers have different times in the first place?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 1:37 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
The database should be able to do this. In SQL Server, set a default value for the column to GETDATE().


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 2:03 pm 
Regular
Regular

Joined: Mon May 16, 2005 2:15 pm
Posts: 59
k-dub wrote:
The database should be able to do this. In SQL Server, set a default value for the column to GETDATE().


FYI: Defaults only work on an INSERT statement. To do this on an UPDATE statement the user would need a trigger.

Bob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:57 pm 
Newbie

Joined: Mon Dec 05, 2005 9:48 pm
Posts: 3
Thanks for the response.

octavius wrote:
Why do the servers have different times in the first place?


I don't think the timestamp will be much different on web & database servers. But I thought it may not be good idea to rely that web & database servers have exact timestamp with nano second precision. Any thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 9:49 pm 
Newbie

Joined: Mon Dec 05, 2005 9:48 pm
Posts: 3
KPixel wrote:
If NHibernate is running on the web server, I don't know how it can use the datetime of the database server. So you probably have to do this yourself...


Thanks.

You mean, by directly firing a udpate sql query? I prefer not to do that. Looks inevitable now.

Also, I thought it is pretty common to have hibernate running outside databse server. If yes, isn't the problem I am facing very common (like last updated time etc)?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 11:24 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
You can either .NET Remoting or a Web Service (or any other tech) to get the datetime of the database server...

In one of my projects, I used remoting to use the datetime of the server in clients (WinApps).

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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