-->
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.  [ 2 posts ] 
Author Message
 Post subject: Custom SQL while saving
PostPosted: Fri Jun 25, 2004 6:35 am 
Newbie

Joined: Fri May 14, 2004 1:33 pm
Posts: 4
Hi all,

is there a way to associate custom SQL to an object column while saving? What I want is this?

I have a class with a composite key being:
- parentId
- sequence

the sequence should be generated upon insertion and for each parentId, using something like "COALESCE(MAX(sequence), 0) + 1" (this is the easiest way). The other choice is to get that number, associate it to the composite id, and then save the object. But this approach is too troublesome, as it means having to do a select first, and only afterwards being able to persist the object...

Any ideas?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 1:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Its not possible.

You would need to call the SQL using a separate SELECT statement, and then assign it to the object.

This makes sense if you wthink about it. How could Hibernate retrieve the generated id after the INSERT?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.