JPA Criteria: issue of querying properties of subclass -
i using hibernate 4.3.6.final, supports jpa 2.1. need build complex query based on user input. got rest done , working, still have problem. let's put metamodel or other solutions aside see how current problem can solved.
the following class structure , relationships:
class baseobject implements serializable { } class extends baseobject{ @onetomany(mappedby = "aref", fetch = fetchtype.lazy, cascade = {cascadetype.persist, cascadetype.remove, cascadetype.merge}, orphanremoval = true) private list<b> blist; } class b extends baseobject { @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "aref") private aref; } //-------------note subclass of b------------ class c extends b { @onetomany(mappedby = "cref", fetch = fetchtype.lazy, cascade = {cascadetype.persist, cascadetype.remove, cascadetype.merge}, orphanremoval = true) private list<d> dlist; } class d { @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "cref") private c cref; string name; }
now want list objects whose, after join, value of "name" field in class d "john". here have:
criteriabuilder cb = entitymanager.getcriteriabuilder(); criteriaquery cq = cb.createquery(); root<a> root = cq.from(a.class); criteriaquery<object> select = cq.select(root); join bjoin = root.join("blist"); join cjoin = cb.treat(bjoin, c.class); join djoin = cjoin.join("dlist"); //error happens here predicate p = cb.equal(djoin.get("name"), "john"); cq.where(p); query query = em.createquery(select); list<a> result = query.getresultlist();
but keep getting following error:
unable locate attribute the given name [dlist] on managedtype [baseobject]
is doing correct? how fix problem? thought using treat method should find property on subclass.
thanks!
Comments
Post a Comment