My deep relationship problem for JPA

View: New views
2 Messages — Rating Filter:   Alert me  

My deep relationship problem for JPA

by Tony Huang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi, All
I created 3 classes: Class A has a collection of class B; B has a collection of class C
When saving the instance of A to DB table, I want also save the children and grandchildren of B and C.
But I failed to do this.
 
My question is JPA support the 3 layer hierarchy?
What should I do to solve my problem?
 
Thanks
 
Tony Huang
Developer,Foundation
The Active Network,LTD (Xi’an)
 
Mobile 86-13389240842
Skype tony.huang214
QinFengGeD201 68 Keji No. 2 Rd.
Xian, China 710075
 
 
 

Re: My deep relationship problem for JPA

by tware :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Tony,

   You should be able to do this by enabling cascading on your relationship.

   Something like this:

     @OneToMany(cascade={PERSIST})

   With this setting, when you call persist on an object, all the objects on the
other side of this relationship will be automatically be persisted.

-Tom



Tony Huang wrote:

> Hi, All
> I created 3 classes: Class A has a collection of class B; B has a
> collection of class C
> When saving the instance of A to DB table, I want also save the children
> and grandchildren of B and C.
> But I failed to do this.
>  
> My question is JPA support the 3 layer hierarchy?
> What should I do to solve my problem?
>  
> Thanks
>  
> *Tony Huang*
> Developer,Foundation
> The Active Network,LTD (Xi’an)
>  
> _Tony.Huang@... <mailto:Tony.Huang@...>
> Mobile 86-13389240842
> MSN _hdp214@... <mailto:hdp214@...>
> Skype tony.huang214
> QinFengGeD201 68 Keji No. 2 Rd.
> Xian, China 710075
> _www.ActiveNetwork.com_ <http://www.ActiveNetwork.com>
>  
>  
>