-->
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: PK/ID Generation Question - Static text + incrementing id
PostPosted: Wed Sep 01, 2004 11:17 pm 
Newbie

Joined: Fri Aug 13, 2004 12:17 pm
Posts: 12
Location: St. Louis, MO
I'd like to have an ID where you have ABC-1 where ABC- is static and the 1 is an incrementing (DB independent, if possible) number. I understand that this will entail using an id generator of type Assigned.

My question is, have any of you done an ID like this and if so, how? I'd like to restrict all database access to hibernate, if possible. The databases that will be running this app are postgresql and oracle, so sequences are an option, but again, I'm not sure how this would be implemented without using straight jdbc.

Any help would be appreciated.

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 2:11 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Your can also write your own id generator, see http://www.hibernate.org/50.html.

If you use assigned id's you cannot use saveOrUpdate and cascading update (which uses saveOrUpdate even if you call save) unless you write an appropriate interceptor, see http://forum.hibernate.org/viewtopic.php?t=933521 for more details on that.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 8:59 pm 
Newbie

Joined: Fri Aug 13, 2004 12:17 pm
Posts: 12
Location: St. Louis, MO
Thanks for your reply. What would you guys suggest that I do if I want something along these lines: A parent class which has a set of child classes where the child classes id is a composite of the parent id and an incrementing id for the child which is a unique sequence for each parent-child relationship.

Sorry if this is something really simple, but I've looked through the documentation and hibernate in action and couldn't seem to find what I was looking for.

Example:

Parent #1
--------
id = abc

Child #1 of Parent #1
--------
id = abc - 1

Child #2 of Parent #1
--------
id = abc - 2

Parent #2
--------
id = xyz

Child #1 of Parent #2
--------
id = xyz- 1

Child #2 of Parent #2
--------
id = xyz - 2


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.