It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes which generator type to use..? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "which generator type to use..?" Watch "which generator type to use..?" New topic
Author

which generator type to use..?

Jigar Gohil
Greenhorn

Joined: Dec 04, 2008
Posts: 11

Hello All,
I have a situation in which I am having a database with one sequence & trigger per table. The trigger simply sets the Primary key of a table before inserting any record using the sequence created for that table.
Using sequence as generator type doesn't work coz of the triggers i have placed. The sequence gets incremented twice

I want that primary key to be returned while saving the object.

can anyone suggest which generator type can i use..?

Thanks in advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You could just use an assigned generator. But then again, is there an issue with the sequence getting incremented twice? Do you still have a not null, unchanging, unique value for your primary key?



JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Well, it really sounds messy, because your sequence generator is your custom-built trigger. So, typically, either we generate our ids ourselves, or we allow a sequence or id generator on the database do it. With your solution, you're sorta blazing new ground, and it doesn't seem to fit into any of the standard strategies.

Jigar, I edited your subject line to remove the 'urgent' request. Here's what we find when posts are marked urgent:

JavaRanch Experience with URGENT Request

Good luck!
Jigar Gohil
Greenhorn

Joined: Dec 04, 2008
Posts: 11

Thank You Paul and Cameron...
First of all the reason for using triggers for id generation is... m having no. of procedures which inserts data into the tables.. its not only the application through which data is getting inserted. So, I wanted the sequences to be shared between application code and back-end procedures.

n e ways...I have applied one solution which i could think of...i.e
I have used sequence as my generator type & modified my triggers with one condition as follows:




Its simple with hibernate insert query...already there will be an id value... so no need to use the sequence again....


Any one with better solution than this would be appreciated...

Thank You, CodeRanch.


 
jQuery in Action, 2nd edition
 
subject: which generator type to use..?