-->
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: Dilemma - Oracle Timestamp or Date
PostPosted: Wed Apr 23, 2008 10:18 am 
Newbie

Joined: Fri Aug 17, 2007 2:11 pm
Posts: 19
Hi

I apologize if this question has been answered already. I searched through the forums all of yesterday and googled with no luck.

I am running an Oracle 9i database and using a 10G driver - ojdbc14_10-2-0-3.jar (copied to lib folder) , we are upgrading our database to 10G soon.

I'm attempting to reverse gen my schema into model classes. I am also a custom strategy ( copied from a forum post here ) that annotates my version column correctly.

All my tables have timestamp columns for audit.

Code:
CREATE TABLE CATALOG
(
  CATALOG_ID     INTEGER                        NOT NULL,
  CATALOG_NAME   VARCHAR2(50 BYTE)              NOT NULL,
  DATE_CREATED   TIMESTAMP(6)                   DEFAULT systimestamp          NOT NULL,
  ADDED_BY       INTEGER                        NOT NULL,
  DATE_MODIFIED  TIMESTAMP(6)                   DEFAULT systimestamp          NOT NULL,
  MODIFIED_BY    INTEGER                        NOT NULL,
  ENABLED        CHAR(1 BYTE)                   DEFAULT 'N'                   NOT NULL,
  VERSION_ID     INTEGER                        DEFAULT 1                     NOT NULL
);



The generated code maps my timestamp columns to Serializable
Code:
   @Column(name = "DATE_CREATED", nullable = false)
   @NotNull
   public Serializable getDateCreated() {
      return this.dateCreated;
   }


I understand this is an Oracle problem, but is there anyone who has a workaround for this ?

If I do change these fields to Date type, I do get the expected results.
My gut tells me that I should change my fields to Date type. The only issue I still see is that even with Date fields, the generated methods are not annotated with @Temporal(TemporalType.TIMESTAMP)


Can anyone offer some advice ?

Thanks
Franco


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 25, 2008 9:33 am 
Newbie

Joined: Fri Aug 17, 2007 2:11 pm
Posts: 19
I modified my fields to Date datatype in Oracle.

After reverse gen this time, I did get @Temporal(TemporalType.DATE) and I changed it to @Temporal(TemporalType.TIMESTAMP)

The problem I encountered then was that Hibernate strips off time after an update.

I then annotated the columns this way
@Column(name = "DATE_MODIFIED", updatable = false, insertable = false)

and wrote a before insert/update trigger to update these datetime values.

The only problem I might encounter in future is when I have to update a datetime field from the UI

Anyone here using an Oracle 9i db and above have any ideas ?

Thanks
Franco


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.