-->
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: Insert data and get the primary key based on seq Postgresql
PostPosted: Tue May 18, 2004 6:32 am 
Newbie

Joined: Tue May 18, 2004 6:22 am
Posts: 2
Hi All,
I am new to Hibernate. From last some days I have searched most of the forum post and Hibernate Ref documentation.

Here is my problem. Coupld someone help me.

I have got very complex Database schema and presently I am using handwritten DAO with postgreSQL database to insert the record using database sequence.

Is it possible from hibernate to insert the record(I know how to use sequence with hibernate) and return the key so that this could be used to insert in ref table.

For ex: I got user table and usergroup which has many-to-many relationship using the ref table user_usergroupmapping.
Now if I can insert the record in user table and get the key, similarly for usegroup then I can insert the reference keys in the mapping table.

How do i do it with hibernate or is there any other way to do it in hibernate?

Any link to documentation or tutorial will help.

Regards,
Umesh


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 8:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You just set the relationship between the objects in your java code and safe them, Hibernate will manage the relationship table. There is no need to mess around with primary keys manually.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 8:11 am 
Newbie

Joined: Tue May 18, 2004 6:22 am
Posts: 2
but is there any way to get the key to be used later for setting in other objects?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 8:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You don't use the key for setting in other objects, you set up object relationships when using an OR-Mapper. However, the generated id is returned from save, and of course also set on the saved object.


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.