I have 2 Classes, Parent and Child, with a @OneToMany
relationship. Every parent has 0 or more children.
@OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.REMOVE})
The Parent class has also other fields like the name.
I'm in a Container env, so my UI is made of JSP.
When I want to change the Parent
object I have to pass it to a servlet and down to the client browser. In the web page I don't want to put all the children info开发者_StackOverflow社区rmation, I only whant to have a text field for the parent name.
When the control return to me, I'd like to create a new Parent
object with the brand new name and to merge
with the EntityManger
without worrying about the children.
I think the correct way is actually to load the existing Parent object, set the name property to the new value, and save it. That is actually what you are doing.
So your form needs one field for the name that the user can enter, and one hidden field containing the id of the parent. When the form is posted, you load the Parent object by the id, set the name to the value entered, and save.
精彩评论