Forums Register Login

which generator type to use..?

+Pie Number of slices to send: Send

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.
+Pie Number of slices to send: Send
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?


+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send

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.


Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1122 times.
Similar Threads
what i will use in hbm when we use sequence at backend side ?
insert expression as primary key, taking advantage of generator class mappings?
Hibernate Mapping problem because no primary key in database
why my oracle sequence id increases by 2 when I use hibernate to insert
ejbcreate return type
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:31:08.