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.  [ 1 post ] 
Author Message
 Post subject: Inserting/mapping literal timestamp values
PostPosted: Thu Aug 02, 2007 8:30 am 
Newbie

Joined: Thu Aug 02, 2007 8:09 am
Posts: 1
Hi, I have a timestamp property on my entity which is supposed to be updated every time the entity is updated (and it has to be set on insert as well). A fairly typical edit audit stuff ...

Setting the timestamp is easy when done with JVM. I simply have a method marked with @PreUpdate/@PrePersist

Code:
  @PrePersist
  @PreUpdate
  protected void updateAuditInfo() {
      auditTimestamp = new Date();
}


This works, but what if I want the auditTimestamp to be set by the database using CURRENT TIMESTAMP? So, what would get inserted when the entity is persisted would be something like INSERT INTO MYTABLE(... fields ..., AUDIT_TS) VALUES (... field values..., CURRENT TIMESTAMP).

How would I achieve that? @Version is not an option as there is another (int) column that is the version. I tried using a custom user type by extending org.hibernate.usertype.UserType, but that doesn't work since you cannot set the literal value CURRENT TIMESTAMP on a PreparedStatement ... I also tried setting the timestamp property type to org.hibernate.type.DbTimestampType, that didn't help either.

I'm using Hibernate 3.2 with Annotations and the EntityManager,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.