-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to save/update an entity with a timestamp from the db?
PostPosted: Fri Jun 06, 2008 10:20 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
Rather than Hibernate providing a copy of the datetime for the timestamp, I'd like to be able to specify that the database getdate() or equivalent function to be used for the insert/update.

Having surveyed the forums & literature for this, there doesn't appear to be a neat way of doing this. One would have to use an annotation as follows:

@Temporal(TemporalType.TIMESTAMP)
@Column(name="InputTime", insertable=false, updatable = false)
@Generated(GenerationTime.ALWAYS)
private Date inputTime;

and then write an update trigger for the column. However this doesn't satisfy the case where you don't want the timestamp field updated every time the row is updated.

It would be nice to have an annotation such as

@Temporal(TemporalType.TIMESTAMP, source="database")
@Generated(GenerationTime.ALWAYS)
@Column(name="InputTime", insertable=false, updatable = false)
private Date inputTime;

Are there any plans to introduce such a feature?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 06, 2008 10:54 am 
Regular
Regular

Joined: Wed Apr 09, 2008 10:28 am
Posts: 52
try this @Column(name="InputTime", insertable=false,updatable=false,columnDefinition="timestamp not null default current_timestamp")


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 5:56 am 
Newbie

Joined: Mon Jan 21, 2008 7:30 am
Posts: 9
Sorry but this didn't work, neither did permutations such as

@Temporal(TemporalType.TIMESTAMP)
@Column(name="InputTime", insertable=false, updatable=false, columnDefinition="timestamp not null default getdate()")
@Generated(GenerationTime.ALWAYS)

as the database I'm running against is Sybase.


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