[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5051) JPA 2 Criteria Query with Object as Parameter not Working
mohamed shdid (JIRA)
noreply at atlassian.com
Tue Apr 13 14:48:58 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5051?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36425#action_36425 ]
mohamed shdid commented on HHH-5051:
------------------------------------
i also this bug
this my code
Map map=new HashMap ();
map.put("account.role", roleDropDown.getModelObject());
AdminDbOperation.list(Person.class,map);
class AdminDbOperation{
public static List<Object> list(Class cls,Map param) {
entityManager = getEntityManager();
CriteriaBuilder cBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery cQuery = cBuilder.createQuery(cls);
Root root=cQuery.from(cls);
for (Object objKey: param.keySet()) {
Path att=root.get(objKey.toString());
cQuery.where(cBuilder.equal(att, param.get(objKey)));
}
TypedQuery q = entityManager.createQuery(cQuery);
return q.getResultList();
}
}
> 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