java - Joining tables without relation using JPA criteria -
i have 2 tables no modeled relation:
table comm
columns:
name date code
table persondesc
columns:
code description
relationship between 2 tables many 1 (many comm 1 persondesc):
com.code = persondesc.code
these 2 tables mapped annotations have no relation declared.
what i'm trying select comm
table ordered persondesc.description
.
how can jpa , hibernate?
so if classes have no "relation" query like
select a, b b a.somefield = b.otherfield order b.anotherfield
which can achieved using jpa criteria, something like
criteriabuilder cb = emf.getcriteriabuilder(); criteriaquery<a> crit = cb.createquery(a.class); root<a> aroot = crit.from(a.class); root<b> broot = crit.from(b.class); aroot.alias("a"); broot.alias("b"); crit.select(aroot); predicate fieldequals = cb.equal(aroot.get(a_.somefield), broot.get(b_.otherfield); crit.where(fieldequals); crit.orderby(cb.asc(broot.get(b_.anotherfield)));
... or redesign classes , developers favour.
Comments
Post a Comment