-->
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: Auto generated value as column value
PostPosted: Thu Jan 08, 2009 9:07 am 
Newbie

Joined: Mon Nov 10, 2008 8:43 am
Posts: 8
Hi all,

I want to set an auto generated value in a column when ever a record is created in a table. The logic of creation of this value is as such :

Value = base 36 converted value of primary key or the ID

Is it possible to do using the Hibernate API or extending the hibernate API. I am using auto increment feature to increase the id by 1 each time a record is created.

Regards,
Nitin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 9:12 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
Use increment generator in ur mapping file. (.hbm.xml file)..

For eg.,

<id name="userId" type="java.lang.Long">
<column name="user_id" />
<generator class="increment" />
</id>


here user_id is autoincrement column of users table.

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 9:58 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I guess you have to check your database for that kind of functionality. Hibernate doesn't generally generate values for you automatically. The only exception are some of the ID generators.

It might be possible to implement some kind of auto-generation with a custom UserType, but not if you depend on the auto-increment value that is generated by the database.

On the other hand, Hibernate has support for calculated properties. Eg. properties that are not stored in the database, but are calculated on the fly (using SQL) each time the data is read from the database. See <property formula=...> at http://www.hibernate.org/hib_docs/v3/re ... n-property


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.