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.  [ 4 posts ] 
Author Message
 Post subject: sequence generation embed in insert & single call for PK
PostPosted: Fri Jan 27, 2006 4:33 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
There are two issues, that I am having a hard time figuring out the best approach, with Sequence generation for PK and associating them by FK's:

1) I noticed that there seems to be no way to get hibernate to include a myseq.nextval in the insert statement for the object. Any ideas on this?

2) It would be nice that if hibernate notice, that the parent and FK-dependent objects were getting inserted all at once (or should go in one shot), that it would get the parent_id and assign as FK ids to the dependent objects all in one statement to the DATABASE – one IO not MANY (get Ids first, then do inserts for each of the objects). In Oracle you’d send a PLSQL block like pseudo code:

BEGIN
Insert into parent values(parent_seq.nextval, ‘data,data,data’);
fk_parent:= parent_seq.currval;
Insert into child values (fk_parent, ‘child data1’);
Insert into child values (fk_parent, ‘child data2’);
END;

Is there any such way in Hibernate?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 4:53 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
You can of course implement your own generator but I do not think that this would allow to save data in shot.

Even your example will probably not do this. It will issue a select sequence.nextval(); and then insert the value.
Of course you are closes to the datbase.

You can define generated values for hibernate. I am not sure if this works for primary keys. In this case Hibernate will have to issue a select to read the data after your insert, which does not at all save a query.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 5:10 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
re: #1 does a costomer generator even help to have the generated key embedded in the insert statement - I think not... but unsure.

RE: #2 My example is setup to show that if you send one database call with a plsql block as shown (in Oracle), then you can accomplish what I am talking about.

Also I realize that there is "PROCEDURE/FUNCTION" features in 3.0+ but then I would have to create one big massive java object that would have the properties of the child defined in it...perhaps as a component... but then it would be a bear to pass MANY child (have to be an array) as a parameter to the PROCEDURE...

a 1-M of Person and Address might define something like:
<class
name="Person"
table="Person">
...
<sql-insert callable="true">{call createPerson (?, ?, ?, ?)}</sql-insert>
...
</class>
Yet one of the parameters to the createPerson procedure would have to be a list of Addresses... how can that be done - customType?? Sounds like a lot of trouble... and I am not even sure if it is going to work. Any one have ideas/suggestions/better solutions?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 1:19 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
can any hibernate-TEAM developers chime in???
Thanks.


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