-->
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.  [ 4 posts ] 
Author Message
 Post subject: "generated" attribute of "property" tag inserts NULL value
PostPosted: Wed Sep 09, 2009 9:22 am 
Newbie

Joined: Wed Sep 09, 2009 9:02 am
Posts: 3
I'm having a problem inserting timestamp values to "created_date" and "modified_date" columns, when i save an entity, no exception is throwed but NULL value is inserted into "created_date" and "modified_date" columns instead of a timestamp, all other columns(which do not use "generated") are inserted with proper data.

I tried using <timestamp> but the results were same.

I'm using MySQL 5 and Hibernate 3.3.1

This is the mapping definition from one the mapping files

Quote:
<property name="createdDate" column="created_date" update="false"
insert="false" generated="insert" access="field" type="timestamp" not-null="true" />

<property name="modifiedDate" column="modified_date" update="false"
insert="false" generated="always" access="field" type="timestamp" not-null="true" />


In dao class the getter/setters are as follows
Quote:

public Date getCreatedDate() {
return createdDate;
}
private void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
private void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}


Please help


Top
 Profile  
 
 Post subject: Re: "generated" attribute of "property" tag inserts NULL value
PostPosted: Mon Sep 14, 2009 11:57 pm 
Beginner
Beginner

Joined: Thu Feb 21, 2008 3:31 pm
Posts: 34
Hi,

I am having the exact same issue, except I'm using annotations:

Code:
@Generated(GenerationTime.INSERT)
   @Temporal(TemporalType.TIMESTAMP)
   @Column(nullable = false, updatable = false, insertable = false)
   public Date getDate()
   {
      return date;
   }



I tried removing the null constraint, but the value still did not get inserted. I also tried setting the date manually (I left the annotation on the method), but the annotation does appear to be triggering something in hibernate to set the value on insert as it gets set back to null.


Any ideas what else to try? Has anyone gotten this working?


Thanks,
Walter


Top
 Profile  
 
 Post subject: Re: "generated" attribute of "property" tag inserts NULL value
PostPosted: Tue Sep 15, 2009 12:49 am 
Beginner
Beginner

Joined: Wed Jun 17, 2009 9:03 pm
Posts: 31
Location: mumbai
Hi

Kindly have a look at this may be this can help.

[url]

viewtopic.php?f=1&t=954687&view=next
[/url]


Top
 Profile  
 
 Post subject: Re: "generated" attribute of "property" tag inserts NULL value
PostPosted: Tue Sep 15, 2009 7:11 pm 
Beginner
Beginner

Joined: Thu Feb 21, 2008 3:31 pm
Posts: 34
Hi,

Thanks for your reply.

That would work, but it seems that my particular case, that an interceptor would have additional overhead without much gain.

Since I'm using envers and the only entities that I track the update time are all audited, this is a mute point. I'll just leave the code to set the date in the constructor.


Thanks,
Walter


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