我正在尝试使用JPA 2.0的标准查询语句与Hibernate的底层实现。在尝试访问子类属性时,我遇到了困难。
以下是实体的简要描述:
- Class A (which is a Entity & a Table by itself)
- Class B (which is a Entity & a Table by itself)
- Class A has OneToMany relationship with B
- Class AB & BA are child classes of B (Both are entities but are not mapped to any tables. It holds few properties specific to it.)
- Let us suppose both classes AB & BA has a property '''symbol'''
现在开始进行条件查询:
CriteriaBuilder qb = futuresEntityManager.getCriteriaBuilder();
CriteriaQuery<A> query = qb.createQuery(A.class);
Root<A> a = query.from(A.class);
Join<A,B> b = a.joinSet("aLegs", JoinType.INNER);
现在当我形成谓词时:
predicate=qb.and(qb.equal(a.get("id").get("accountId"), "1234"));
predicate=qb.and(predicate,b.get("symbol").in(input.getSymbol()));
-----由于b没有持有对符号的引用,所以上述行在运行时不起作用。只有子类AB和BA才拥有它。
如何在此查询中访问子类的属性?我必须为符号断言包括AB和BA两个类。
谁能帮助我解决这个问题?