I have a simple data model in JPA (hibernate) consisting of many to one and one to one relationships similar to this:
town -> state -> governor -> nation -> continent
where town is many to one to state, state is one to one to governor, governor is many to one to nation and nation is many to one to continent.
I would like to fetch a single town instance by its unique Id and also eagerly fetch its related state, governor, nation and continent using ejbql. I believe the proper ejbql is:
select t from town t
join fetch t.state s
join fetch s.governor g
join fetch g.nation n
join fetch n.continent c
where t.id=?id
Hiberante generates the correct sql from this ejbql, but when I do myTown.getState().getGovernor(). I get back a null object for my governor. Why is hibernate not populating the governor? It seems like it doesn't want to populate objects more than one level up the tree. Anybody see what I'm doing wrong?