-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using the sql function to set the field value.
PostPosted: Wed May 03, 2006 10:42 am 
Newbie

Joined: Fri Oct 22, 2004 10:55 am
Posts: 17
Hibernate Version: 2.1.6.
Database: Sybase 11.9.2

I have a pojo which has 2 fileds. I am trying to figure out how to write the property element in hibernate xml. I want these fields to be set using the sql function as follows:

1. AddDate: I want this field to be set using the sql function getdate() only on insert.
2. UpdateDate: I want this field to be set using the sql function getdate() on insert and update.

When I read the above fields I want to get the data stored in the database. I do not have option to use the trigger and I have to set it using the database date.

Is it possible?
I would like to avoid using the interceptor to set these fields as it would require the extra sql query. Basically I want hibernate to generate the insert/update with the getdate() function.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 11:31 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
Yep - take a look at http://www.hibernate.org/hib_docs/v3/re ... -generated - that should do what you want.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 11:52 am 
Newbie

Joined: Fri Oct 22, 2004 10:55 am
Posts: 17
According to the document. [b]Generated properties are properties which have their values generated by the database.[/b].

I do not want the database (trigger) to generate these values. I want the call getdate() to be part of insert/update statements.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 12:10 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
Sorry - I missed that you don't want to use triggers. As I understand it you should be able to use http://www.hibernate.org/hib_docs/v3/re ... -timestamp without triggers to implement your UpdateDate but not AddDate.

If there isn't much else on your POJO you could always do it by specifying custom SQL for insert and update.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 1:23 pm 
Newbie

Joined: Fri Oct 22, 2004 10:55 am
Posts: 17
Thanks. Looks like it will do the trick in version 3 but I am using the 2.1.6 where there is no source attribute for timestamp property.


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