I am using Hibernate 5 & Spring Data.
Inside my PartyDao
, I have the following method:
@Query("from Party where id in :partyIDs")
List<PartyTO> loadByIDs(@Param("partyIDs") List<Long> partyIDs);
I am calling it like this:
partyList = partyDao.loadByIDs(userPartyIDsList));
but I am getting a list of Hibernate proxy objects (with all the fields set to null
and a handler
field of type org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer
).
This makes no sense to me! Why is Hibernate not loading the objects FROM the query root I am specifying?
I changed it to:
@Query("select party from Party party where party.id in :partyIDs")
List<PartyTO> loadByIDs(@Param("partyIDs") List<Long> partyIDs);
to try to make it more explicit that that I want this object fetched, but it's still returning the proxy objects. Is there something I'm missing? I don't know how I would make it fetch itself.
EDIT:
The proxy object actually has an attribute called target
, which has all the attributes set. Why are they not placed into the object itself?
I am not getting a "lazy initialization exception", but a NullPointerException
inside a Comparator
that is sorting the parties by name:
...
return o1.name.compareTo(o2.name);