-->
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.  [ 5 posts ] 
Author Message
 Post subject: generate property value with sequence
PostPosted: Mon Sep 24, 2007 11:27 am 
Newbie

Joined: Mon Sep 24, 2007 11:14 am
Posts: 2
I need Hibernate to select the value for a field mapped as a property from a sequence when inserting, just like it does for id's.
I can't use triggers on the DB, so mapping with generated="insert" is not an option. Just Hibernate doing "select next_val('some_sequence')" would do. Is it possible?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 5:02 am 
Newbie

Joined: Thu Apr 26, 2007 9:42 am
Posts: 14
Yes. use 'formula' property for that attribute mapping instead of column like:
formula="SELECT ..." the select to extract the next value from sequence.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 5:37 am 
Newbie

Joined: Thu Apr 26, 2007 9:42 am
Posts: 14
Sorry, I think it is wrong what I said before.
It doesn't work like this.
Maybe to have a method into your code that retrieve the next value from sequence and setting the property with this value before saving the object.
(and having maybe update="false" on that property)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 10:03 am 
Newbie

Joined: Mon Sep 24, 2007 11:14 am
Posts: 2
Yes, I could do something like that. However, I've found that apparently it's possible to define custom insert sql for mapped classes, with a <sql-insert> tag on the mapping file. I haven't tried it yet, but I'm thinking that maybe replacing the "?" corresponding to the pk with something like 'select next_val from _sequence_' might work.

Anyway, thanks for replying crista_drg!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 02, 2007 10:06 am 
Newbie

Joined: Thu Apr 26, 2007 9:42 am
Posts: 14
Yes, it could be a solution, I talked about it into:
http://forum.hibernate.org/viewtopic.php?p=2365993


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