Hello,
I have create a id column (primary key, int) and I didn't use any generator to create the primary key.
I use spring framework's hibernatetemplate's save function to insert a record into database.
because the Id has a customize rule, which is date+'0000', for example.
So I need to manually create and assign the id.
I am thinking if I can get the primary or unique constraint when doing insert action(save), and let the insert action in a while loop until save successfully.
here is some of the codes:
boolean success = false;
while (success==false) {
try {
vo.id = createId(...);
save(vo);
success = true;
}catch(xxxException e) {
}
}
The loop is finish until success==true.
Is it possible to do this, or is there any other suggestion way for this purpose.
Thank you in advance.
Philip Chen
|