java hibernate question
I have a object (parent object) which has a child object and th开发者_如何学Pythonat child object has another child object in it.
I am using Hibernate and when i fetch the parent object the child object is lazily loaded.
But the child objects child object is Eagerly loaded.
But when i say patient.getChildObject().getChildObject()
it is null.
Can someone explain me how i can fetch the child objects,child object while fetching the parent object?
Thanks
A messy, and not recommended approach, is to store the id of the child-child-object in the child-object. You can then to the following:
ChildChild cc = (ChildChild)
session.load(ChildChild.class, Parent.Child.getChildId());
Not pretty, but should work.
add @ManyToOne(fetch = FetchType.EAGER) or @OneToOne(fetch = FetchType.EAGER) or @OneToMany(fetch = FetchType.EAGER) or @ManyToMany(fetch = FetchType.EAGER) as your need for every child object reference.
精彩评论