-->
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: composite-id & Generator
PostPosted: Wed Mar 16, 2016 4:55 pm 
Newbie

Joined: Tue Jan 12, 2016 12:16 pm
Posts: 10
Hi,

I have a table in database which has 2 primary keys.
These 2 keys are varchar : no choice
1 key is set manually
The other key must be generated dynamically : eg with a PK Generator on a SEQUENCE table.

So, is there a way to have a composite key with 1 assigned key and 1 generated key ?
Or may I call manually my PK generator class to calculate the ID I need and set it as String ?


Top
 Profile  
 
 Post subject: Re: composite-id & Generator
PostPosted: Thu Mar 17, 2016 1:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can manually call the sequence to get a new ID and then assign it manually along with the other key too.
You can also try with a composite-id and see if it works.


Top
 Profile  
 
 Post subject: Re: composite-id & Generator
PostPosted: Thu Mar 17, 2016 7:18 am 
Newbie

Joined: Tue Jan 12, 2016 12:16 pm
Posts: 10
I have to use composite-id, no choice, so I have to assign PK manually.
I do not use SEQUENCE / IDENTITY, I have a specific table storing last PK value for each entity.
Is there a way to call manually a PK Generator Class ?


Top
 Profile  
 
 Post subject: Re: composite-id & Generator
PostPosted: Fri Mar 18, 2016 5:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You cannot call an IdentifierGenerator manually, but you can implement your custom Generator and choose whatever logic you want.


Top
 Profile  
 
 Post subject: Re: composite-id & Generator
PostPosted: Fri Mar 18, 2016 6:07 am 
Newbie

Joined: Tue Jan 12, 2016 12:16 pm
Posts: 10
Ok, instead of calling my PK Generator I will simply call a service (SequenceService) to get the next PK. I just need to isolate this call in order to always increment PK event if the global transaction fails.


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.