-->
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: Problem with Generated Date
PostPosted: Tue Jul 17, 2007 8:03 am 
Newbie

Joined: Tue Jul 17, 2007 7:50 am
Posts: 2
I want to persist the entity generated time using hiebrnate generated properties. In the mapping file I have the following entry.

<property name="generatedTime" update="false" insert="false" type="java.util.Calendar" generated="insert" access="field">
<column name="GENERATED_TIME" not-null="false">
<comment>Report Generated time</comment>
</column>
</property>

My POJO contains the getter and setter for the 'generatedTime' property.

But when I persist the entity , GENERATED_TIME is always set to null. Is there any way to set the current date as the GENERATED_TIME using the mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 5:16 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Is the value in fact generated in the database (please check the table data itself outside hibernate)? If so, is the SELECT issued just after the INSERT? To check this, enable DEBUG logging for org.hibernate.SQL or set hibernate.show_sql to true in your config properties.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 6:58 am 
Newbie

Joined: Tue Jul 17, 2007 7:50 am
Posts: 2
No value is not generated in the database.

But I have used the following approach to get the things working.

<property name="generatedTime" type="java.util.Calendar">
<column name="GENERATED_TIME" not-null="false" default="sysdate">
<comment>Report Generated time</comment>
</column>
</property>

Now this is working fine. But I'm not sure whether this is the correct approach. Could somebody can point out the problem with earlier appproach?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 8:13 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
You need to understand what "generated" means. It means that the value is generated by the database and Hibernate has to re-select the row to learn the value. If you don't setup your table to have a trigger or default value, then generated isn't going to result in anything.

HTH,

Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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.