[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6103) Criteria API based on MapKeyColumn is not working

Oleksandr Alesinskyy (JIRA) noreply at atlassian.com
Tue Sep 6 10:01:11 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6103?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43458#comment-43458 ] 

Oleksandr Alesinskyy commented on HHH-6103:
-------------------------------------------

This is a really nasty bug, making a Criteria API usability questionable for us (this use case is very typical as far as I can see).

> Criteria API based on MapKeyColumn is not working
> -------------------------------------------------
>
>                 Key: HHH-6103
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6103
>             Project: Hibernate Core
>          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.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list