Criteria API based on MapKeyColumn is not working
-------------------------------------------------
Key: JPA-15
URL:
http://opensource.atlassian.com/projects/hibernate/browse/JPA-15
Project: Java Persistence API
Issue Type: Bug
Environment: Hibernate 3.6.1
MySQL 5.0
Reporter: Edwin Dalorzo
Attachments: log.txt, src.zip
I defined an Employee entity having a map of phone numbers, where the key is the type of
phone (home, office, mobile) and the value is the phone number as a String.
@ElementCollection(fetch=FetchType.LAZY)
@CollectionTable(name="emp_phone")
@MapKeyColumn(name="phone_type")
@Column(name="phone_num")
private Map<String, String> phoneNumbers;
Then I tried to write a Criteria API query using a map join, like this:
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Employee> criteria = builder.createQuery(Employee.class);
Root<Employee> employeeRoot = criteria.from(Employee.class);
criteria.select(employeeRoot);
MapJoin<Employee, String, String> phoneRoot =
employeeRoot.joinMap("phoneNumbers");
criteria.where(builder.equal(phoneRoot.key(), "HOME"));
System.out.println(entityManager.createQuery(criteria).getResultList());
You get an NullPointerException
java.lang.NullPointerException
at
org.hibernate.ejb.criteria.path.AbstractPathImpl.prepareAlias(AbstractPathImpl.java:246)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.render(AbstractPathImpl.java:253)
at
org.hibernate.ejb.criteria.predicate.ComparisonPredicate.render(ComparisonPredicate.java:173)
at org.hibernate.ejb.criteria.QueryStructure.render(QueryStructure.java:258)
at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:340)
at
org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:223)
at
org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
at com.dalorzo.Main.main(Main.java:57)
Exception in thread "main" java.lang.RuntimeException:
java.lang.NullPointerException
at com.dalorzo.Main.main(Main.java:64)
Caused by: java.lang.NullPointerException
at
org.hibernate.ejb.criteria.path.AbstractPathImpl.prepareAlias(AbstractPathImpl.java:246)
at org.hibernate.ejb.criteria.path.AbstractPathImpl.render(AbstractPathImpl.java:253)
at
org.hibernate.ejb.criteria.predicate.ComparisonPredicate.render(ComparisonPredicate.java:173)
at org.hibernate.ejb.criteria.QueryStructure.render(QueryStructure.java:258)
at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:340)
at
org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:223)
at
org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
at com.dalorzo.Main.main(Main.java:57)
If you change the query to filter on value instead of key, it works just fine
criteria.where(builder.equal(phoneRoot.value(), "88750372"));
I have attached a log with exceptions as well as the Employee entity and the Main class
containing a main method.
Also, the code in question runs perfectly fine in EclipseLink.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira