-->
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.  [ 3 posts ] 
Author Message
 Post subject: simple parent child persistance
PostPosted: Sat Dec 27, 2008 9:19 pm 
Newbie

Joined: Wed Dec 17, 2008 12:17 pm
Posts: 11
I am using opensessionview
I have Items (parent )and bids (child)

In my application I first create items and save them .

next i create bids add them to the item and save item (because I am using opensessionview no flush is called after adding bids , so when I see the id with the bid it is null ) is this normal or am I doing anything wrong ?


and finally I have a table bid_users

which just has a user_id and bid_id,

the pk for this table is composite key (bid_id, user_id)

I get the userId from session and bid_id from ((Bid)items.getBids().iterator().next()).getId() , but here the bid_id is null and saving the instance bid_users throws sql exception because bid_id is null and bid_id has not nullable constraint ,Please help me resolve this


Top
 Profile  
 
 Post subject: Re: simple parent child persistance
PostPosted: Sat Dec 27, 2008 11:12 pm 
Newbie

Joined: Wed Dec 17, 2008 12:17 pm
Posts: 11
miro_con@yahoo.com wrote:
I am using opensessionview
I have Items (parent )and bids (child)

In my application I first create items and save them .

next i create bids add them to the item and save item (because I am using opensessionview no flush is called after adding bids , so when I see the id with the bid it is null ) is this normal or am I doing anything wrong ?


and finally I have a table bid_users

which just has a user_id and bid_id,

the pk for this table is composite key (bid_id, user_id)

I get the userId from session and bid_id from ((Bid)items.getBids().iterator().next()).getId() , but here the bid_id is null and saving the instance bid_users throws sql exception because bid_id is null and bid_id has not nullable constraint ,Please help me resolve this



in simple terms

parent.getChildren().add(child);
child.setParent(parent);
getSession().save(parent)

I cannot call flush here

and I want the PK for the child but it is null , can I ask hibernate to generate pk with save ?


Top
 Profile  
 
 Post subject: Re: simple parent child persistance
PostPosted: Wed Dec 31, 2008 2:08 pm 
Beginner
Beginner

Joined: Wed May 14, 2008 2:06 pm
Posts: 21
try this

parent.getChildren().add(child);
child.setParent(parent);
getSession().save(child)
getSession().save(parent)

miro_con@yahoo.com wrote:
miro_con@yahoo.com wrote:
I am using opensessionview
I have Items (parent )and bids (child)

In my application I first create items and save them .

next i create bids add them to the item and save item (because I am using opensessionview no flush is called after adding bids , so when I see the id with the bid it is null ) is this normal or am I doing anything wrong ?


and finally I have a table bid_users

which just has a user_id and bid_id,

the pk for this table is composite key (bid_id, user_id)

I get the userId from session and bid_id from ((Bid)items.getBids().iterator().next()).getId() , but here the bid_id is null and saving the instance bid_users throws sql exception because bid_id is null and bid_id has not nullable constraint ,Please help me resolve this



in simple terms

parent.getChildren().add(child);
child.setParent(parent);
getSession().save(parent)

I cannot call flush here

and I want the PK for the child but it is null , can I ask hibernate to generate pk with save ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.