I'm playing around with the JPA 2.1 Entity Graphs, and I've run into the following bug in Hibernate 4.3.6.Final:
Code:
Collection<Integer> propertyValues = createValues(); //Generates a list of 5 ids
Query q = manager.createQuery("from MyEntity where child.property IN (:values));
q.setParameter("values", propertyValues);
EntityGraph<MyEntity> graph = manager.createEntityGraph(MyEntity.class);
graph.addAttributeNodes("id");
Subgraph subgraph = graph.addSubgraph("child");
subgraph.addAttributeNodes("property");
subgraph.addAttributeNodes("id");
q.setHint(QueryHints.FETCHGRAPH, graph);
List<MyEntity> result = q.getResultList();
I get the following exception:
Code:
java.lang.NullPointerException: null
at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)
at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:613)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1900)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1861)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
I did some debugging and found that the following SQL is printed just before the exception:
Code:
select
myentity0_.my_entity_id as my_enti1_16_,
myentity0_.date_created as date_cre2_16_,
myentity0_.child_id as child_id7_16_,
from
testschema.My_Entity myentity0_ cross
join
testschema.Child child1_
where
myentity0_.child_id=child1_.child_id
and (
child1_.child_id in (
?
)
)
If I comment out adding the entity graph, I get no exception as expected, and see the following SQL generated:
Code:
select
myentity0_.my_entity_id as my_enti1_16_,
myentity0_.date_created as date_cre2_16_,
myentity0_.child_id as child_id7_16_,
from
testschema.My_Entity myentity0_ cross
join
testschema.Child child1_
where
myentity0_.child_id=child1_.child_id
and (
child1_.child_id in (
?, ?, ?, ?, ?
)
)
Note the number of "?" in the "in" clause. It appears something about adding an EntityGraph as a query hint causes Hibernate to incorrectly generate the "in" clause, and something internal throws a null pointer.
Help? Thanks in advance.