Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
queries with "in" referencing entities can have some null ids even if they are not #267
Hibernate sometimes proxy some entities which results in certain cases entityManager.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier(entity) to return null even if there is an id set !
In my case, I'm in JPQLSerializer line 429 (ids.add(util.getIdentifier(entity))) and util.getIdentifier(entity) returns null whereas my entity has an id of 498 (entity.getClass().getMethod("getIdDelegation").invoke(entity) = 498) !
The class of that entity is currently "Delegation_$$_javassist_2" which is an Hibernate proxy.
Here is the patch that is necessary. Instead of
one should write
referenced this issue
Nov 5, 2012
MMmh, perhaps you could attach a "EntityIdentifierResolver" to the JPQLSerializer which would do a PersistenceUnitUtil.getIdentifier by default and if the EM is Hibernate, then when creating the JPQLSerializer, it would attach a "HibernateEntityIdentifierResolver" instead which would check for the HibernateProxy...
Like that the "hibernate specific" would be deported to that other EntityIdentifierResolver class.
Moreover, if I'm correct, there's no obligation to convert the list of entity to a list of ids, I think in JPA it's correct to write "where entity in (:collection)" and then jpaQuery.setParameter("collection", Collection), it's the EntityManager which would then resolve it and create the correct SQL query with the ID.