[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5051) JPA 2 Criteria Query with Object as Parameter not Working

Guido Müller (JIRA) noreply at atlassian.com
Tue Mar 30 09:49:32 EDT 2010


JPA 2 Criteria Query with Object as Parameter not Working
---------------------------------------------------------

                 Key: HHH-5051
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5051
             Project: Hibernate Core
          Issue Type: Bug
          Components: entity-manager
    Affects Versions: 3.5.0-CR-2
            Reporter: Guido Müller
            Priority: Blocker


The problem is with this scenario:

2 Entity classes A and B

We have a 1:N relation between A (N) and B (1)

This test fails:
I get one instance of B with the entity manager find method.

I query the database with JPA 2 query to get a list of all instances of A that have the many-to-one property equals the instance got from the 1st step.

Code:
EntityManager em = ...
B b = em.find(B.class, 1L);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<A> q = cb.createQuery(A.class);
Root<A> p = q.from(A.class);
q.select(p).where(cb.equal(p.get(A_.b), b));
List<A> l = em.createQuery(q).getResultList();
em.close();


This does not work but it should. It works properly with EclipseLink. In Hibernate I get this to work when I provide b.getId() as Parameter. But this is not correct!


-- 
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list