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!