-->
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: Oracle SYSDATE instead of java.util.Date in hibernate entity
PostPosted: Mon Oct 08, 2012 4:54 pm 
Newbie

Joined: Fri Oct 05, 2012 3:37 pm
Posts: 2
Hi, I was trying to implement Oracle SYSDATE in all of my hibernate entity classes who extends Auditable abstract class which has createTimestamp and updateTimestamp. Instead of using java.util.Date() for populating these timestamps, I would like to use SYSDATE.

Is there a way of doing it? I found something regarding this in some forums about @Formula(value="select sysdate from dual") which should get sysdate from the DB but for some reason it never worked for me. I always get sysdate as null.

Can somebody please help me on this? Here is my code

Code:
@MappedSuperclass
public abstract class Auditable {

   @Formula(value = "(select sysdate from dual)")
   private Date sysdate;

   @Column(name = "CREAT_USER", length = 20)
   private String creatUser;

   @Column(name = "CREAT_TMSTMP", length = 7, insertable = true, updatable = false)
   private Date creatTmstmp = getSysdate();

   @Column(name = "UPDT_USER", length = 20)
   private String updtUser;

   @Version
   @Column(name = "UPDT_TMSTMP", length = 7, insertable = true, updatable = true)
   private Date updtTmstmp;

   public String getCreatUser() {
      return this.creatUser;
   }

   public void setCreatUser(String creatUser) {
      this.creatUser = creatUser;
   }

   public Date getCreatTmstmp() {
      return this.creatTmstmp;
   }

   public void setCreatTmstmp(Date creatTmstmp) {
      this.creatTmstmp = creatTmstmp;
   }

   public String getUpdtUser() {
      return this.updtUser;
   }

   public void setUpdtUser(String updtUser) {
      this.updtUser = updtUser;
   }

   public Date getUpdtTmstmp() {
      return this.updtTmstmp;
   }

   public void setUpdtTmstmp(Date updtTmstmp) {
      this.updtTmstmp = updtTmstmp;
   }

   public Date getSysdate() {
      return sysdate;
   }

   public void setSysdate(Date sysdate) {
      this.sysdate = sysdate;
   }
}


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.