-->
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: Hibernate annotations and automatic Timestamp
PostPosted: Fri Sep 10, 2010 4:46 am 
Newbie

Joined: Thu Sep 09, 2010 9:57 am
Posts: 5
Hi all,

I have a bean with Date :
Code:
   private Date storageTimestampOrNull;


With an XML mapping, this field is automatically set when inserting into database (it's OK, it's working) :
Code:
   <timestamp name="storageTimestampOrNull" column="StorageTimestamp" source="db" />


I want to use Annotations. No problems for all other fields, including @MappedSuperclass and @Embeddable, but impossible to have this field storageTimestampOrNull set when inserting. Here are my annotations for this field :
Code:
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "storage_timestamp", insertable = false, updatable = false)
   @Type(type = "my.package.UtcTimestampUserType")
   @Generated(GenerationTime.ALWAYS)
   private Date storageTimestampOrNull;

UtcTimestampUserType is an UserType to force UTC storage.
I have done many searches, and many tests, such as :
Code:
@Column(columnDefinition = "timestamp default current_timestamp on update current_timestamp", ...)

or
Code:
@Column(nullable = false, ...)

but nothing to do, storageTimestampOrNull is always null !

Note, for the moment, I'm working only with unit tests with HSQLDB, the target is PostgrSQL.

Versions used :
  • org.hibernate:hibernate:3.2.7.ga
  • org.hibernate:hibernate-annotations:3.2.1.ga
  • hsqldb:hsqldb:1.8.0.10
but I can change ...

Any idea ?

Thanks

Xavier


Top
 Profile  
 
 Post subject: Re: Hibernate annotations and automatic Timestamp
PostPosted: Sat Sep 11, 2010 5:14 am 
Newbie

Joined: Tue Aug 24, 2010 7:04 am
Posts: 14
With insertable = false in your column annotation you removed the column from any insert statement. I only use this annotation, when I want to provide a second field for the identifier of a reference. So both fields references the same column like @Column(insertable=false, updateable=false ...) private Long roleId; @ManyToMany(...) private Role role;

Kind regards
Michael


Top
 Profile  
 
 Post subject: Re: Hibernate annotations and automatic Timestamp
PostPosted: Tue Sep 14, 2010 9:06 am 
Newbie

Joined: Thu Sep 09, 2010 9:57 am
Posts: 5
Hi Michael,

michaeler wrote:
With insertable = false in your column annotation you removed the column from any insert statement. I only use this annotation, when I want to provide a second field for the identifier of a reference. So both fields references the same column like @Column(insertable=false, updateable=false ...) private Long roleId; @ManyToMany(...) private Role role;


Without insertable = false, I have this error :
Code:
org.hibernate.AnnotationException: Cannot have @Generated property and insertable columns


Without updatable = false, I have this error :
Code:
org.hibernate.AnnotationException: Cannot have @Generated(ALWAYS) property and updatable columns


So, insertable = false, updatable = false is needed with @Generated(ALWAYS).


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.