-->
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.  [ 2 posts ] 
Author Message
 Post subject: how to insert timestamp using database time.
PostPosted: Thu Jul 28, 2011 3:59 pm 
Newbie

Joined: Thu Jul 28, 2011 3:53 pm
Posts: 2
Hi all
I have Hibernate entity class User that contain "statusDate",
When I persist the object to the DB I do:
Code:
User user = new User();   
user.setStatus(ACTIVE);   
user.setStatusDate(new Date()); 
User user = new User();
user.setStatus(ACTIVE);
user.setStatusDate(new Date());


So I am reading the date & time from the local machine.
Is there any way I can update the statusDate with oracle's date and time?
I want to avoid native query like:

Code:
INSERT INTO " user " ("name", "status","statusDate") VALUES ("Sharon", "ACTIVE", SYSDATE) 


I can not change database at all, so all the setting has to happen in hibernate. i try to use formula with annotation, but if I set the
Code:
@formula("sysdate")
private Date statusDate;

both the select and insert will use the current date. how to solve this


Top
 Profile  
 
 Post subject: Re: how to insert timestamp using database time.
PostPosted: Wed Sep 21, 2011 1:22 pm 
Newbie

Joined: Mon May 22, 2006 1:00 pm
Posts: 13
We are interested in the same solution - how to use database time in an entity setter - in our case we would like to apply this then in @PrePersist and @PreUpdate events.


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