-->
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: parent child persistence problem
PostPosted: Wed Mar 03, 2010 5:31 am 
Newbie

Joined: Tue Oct 06, 2009 2:03 pm
Posts: 7
I have a parent child relationship

Parent Entity Child Entity, when I persist the child enity I wish to persist the parent.

childEntity.persist()

The parent enity id is autogenerated when persisted.

As you can guess when I call childEntity.persist() I get the id must be set for the parentEntity, before the childEnity can be persisted.

when I call childEnity.persist() I want hibernate to carry out the following actions:

parentEnity.persist()
childEntity.persist()

In my childEnity i have the following relation ship set up


@NotNull
@ManyToOne(cascade = CascadeType.ALL, targetEntity = ParentEntity.class)
@JoinColumn(name="child_parent_id", referencedColumnName="parent_id")
private ParentEntity applicant;

As mentioned it does not work, do I need to set anything else. To get cascade to work , an just want to check you can cascade from child to parent, as well as parent down to child

Cheers


Top
 Profile  
 
 Post subject: Re: parent child persistence problem
PostPosted: Wed Mar 03, 2010 6:28 am 
Newbie

Joined: Tue Oct 06, 2009 2:03 pm
Posts: 7
It does work in a fashion, I have just found out that the parentId is not autogenerated but set by a aspect when parentEntity.persist() is called.

But debugging through the code.

If childEnity.persist() is called it wont call my parentEnity.persist() in my parentEntity_roo.aj.

It will persist under the covers.

So I guess in cases like this you either have auto generation set or you set the id first.


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.