-->
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: @GeneratedValue for non-ID columns possible?
PostPosted: Tue Sep 07, 2010 5:42 am 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hello,

I would like to use a @GeneratedValue annotations on a non-id column, is that possible?
I really searched the docs, but didn't find anything concerning this :/

Thank you in advance, Clemens


Top
 Profile  
 
 Post subject: Re: @GeneratedValue for non-ID columns possible?
PostPosted: Tue Sep 07, 2010 3:35 pm 
Newbie

Joined: Mon Aug 02, 2010 11:14 pm
Posts: 10
Hey,

I am not sure. However I would like to say, that if it is a number then it might be. The only thing I am afraid of is that @generateValue annotation may force the key value to be retrieved, I say this because in mysql the only way you get a recently entered primary key is by using the lastvalue function. So that's why I would say no. But I will try it out and let you know. If you have had a chance to test it, and found answer let us know too. Great question by the way :)

Ramon


Top
 Profile  
 
 Post subject: Re: @GeneratedValue for non-ID columns possible?
PostPosted: Tue Sep 07, 2010 4:06 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
See chapter 2.4.3.5 about generated properties: http://docs.jboss.org/hibernate/stable/ ... c-property

Don't know if that is what you need or not, but should work if the values are generated by the database.


Top
 Profile  
 
 Post subject: Re: @GeneratedValue for non-ID columns possible?
PostPosted: Wed Sep 08, 2010 3:37 pm 
Newbie

Joined: Mon Aug 02, 2010 11:14 pm
Posts: 10
Nice, I like that little snippet. Seems as though a generated value gets added when the field value is. I say this because I was a bit confused on the generate on update part...

Quote:
Some properties are generated at insert or update time by your database.


Am I right to assume that? Or is this something we should test?

SB


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.