3

I have a object (parent object) which has a child object and that 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

1
  • 3
    Can you post your code and mapping?
    – brainimus
    Apr 12, 2011 at 19:41

2 Answers 2

0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.