Hi
I'm going through the examples for parent/child relationships here
http://www.hibernate.org/hib_docs/refer ... child.html
..and it made me wonder about something. If I have a parent object, but I only have the id of my child object, do I need to look up the child object before saving the parent?
E.g. (pseudocode)
Code:
Parent contains Child
Parent p ....; // fully populated by some means
long childId = 123; // perhaps passed in via a form in a JSP
p.setChild(xxxxxx);
getHibernateTemplate().save(p)
So my question is, whats the best way of filling 'xxxx'. Is it enough to do
Code:
Child c = new Child();
c.setId(childId)
p.setChild(c)
and let hibernate do the rest
Or do I have to look up the child myself and give hibernate the fully retrieved object?
Code:
Child c = getHibernateTemplate().get(....);
p.setChild(c);
Thanks