-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to do automatic generation of a non primary key column ?
PostPosted: Tue Dec 07, 2004 7:55 am 
Newbie

Joined: Tue Dec 07, 2004 7:51 am
Posts: 7
I have a table lets say with following fields:

id (which is primary key and of identity type)
id2 (which is a normal column with lets say int data-type)

In the mapping xml for this table, I am using "identity" algorithm for automatic generation of "id" column.

Now the primary key "id" will be generated automatically whenever a new row is inserted into this table. Alongwith the generation of id, I also want id2 to get generated automatically through hibernate. Is that possible ? Can we use some pre-defined algorithm for the generation of a non-primary key column in xml or something like that ?

[/url][/list][/list][/code][/quote][/b]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 8:46 am 
Beginner
Beginner

Joined: Tue Sep 07, 2004 3:58 am
Posts: 23
Had a similiar prob...
I solved it for now with one of two simple hacks:

1) Generate a UID. ThereĀ“s a class somewhere in the javax.rmi package that generates universal identifiers that are garanted to be unique in one JVM. I think its similiar to how the hibernate id is generated.

2) let your class implement the hibernate lifecycle interface and overload the onSave() Method (or add an Interceptor to your config...) and there set the id2 to the value of id ....

i guess there are more elegant solutions, but its better than nothing...

_________________
People keep asking me if i know Tyler Durden....


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