jpa - Criteria Query with BigMoney from Joda Money (Multi-Column field in Entity) -
i have serious issue criteria query.
my entity class looks this:
class x { ... @columns(columns = { @column(name = "pricecurrency", nullable = false), @column(name = "priceamount", nullable = false)}) @type(type = "org.jadira.usertype.moneyandcurrency.joda.persistentbigmoneyamountandcurrency") @basic(fetch = fetchtype.eager) bigmoney price; ... }
and have class y has list<x> xs
.
i have working normal jpa query:
select y y y left join y.xs x group y order sum(y.price.amount)
now i'd transfer criteriaquery. started with:
criteriabuilder cb = entitymanager.getcriteriabuilder(); criteriaquery<y> q = cb.createquery(y.class); root<y> root = q.from(y.class); listjoin<y, x> j = root.join(y_.xs, jointype.left); q.groupby(root);
i tried few things, none of them worked :( here few examples:
path<bigdecimal> x = j.get("priceamount");
or:
path<bigdecimal> x = j.get("price.amount");
or:
path<bigdecimal> x = j.get(x_.price).get("amount");
what doing wrong?
for i'll stick little workaround solution, works expexted:
class x { ... @column(name = "pricecurrency", nullable = false) @basic(fetch = fetchtype.eager) string pricecurrency; @column(name = "priceamount", nullable = false) @basic(fetch = fetchtype.eager) string priceamount; ... public bigmoney getprice() { return bigmoney.of(currencyunit.of(pricecurrency), priceamount); } public void setprice() { this.pricecurrency = price.getcurrencyunit().tostring(); this.priceamount = price.getamount(); } }
now criteria query looks like:
criteriabuilder cb = entitymanager.getcriteriabuilder(); criteriaquery<y> q = cb.createquery(y.class); root<y> root = q.from(y.class); listjoin<y, x> j = root.join(y_.xs, jointype.left); q.groupby(root); path<bigdecimal> = j.get(x_.priceamount); typedquery<y> tq = entitymanager.createquery(q);
Comments
Post a Comment