-->
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.  [ 1 post ] 
Author Message
 Post subject: Can I get the unique or primary key constraint exception?
PostPosted: Tue Mar 11, 2008 3:41 am 
Newbie

Joined: Tue Aug 08, 2006 2:56 am
Posts: 6
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.