CriteriaBuilder aborted [message #646289] |
Thu, 23 December 2010 08:00 |
Tom Eugelink Messages: 817 Registered: July 2009 |
Senior Member |
|
|
Just giving my opinion / FWTW feedback. I've been in the process of moving to using the new CriteriaBuilder API instead of the string queries the last months, and gave up on it yesterday.
Yesterday I had to write a sum query and that was the last drop. Not because I thought I wasn't able to get it working (in the end), but the expected time it would cost me. There was very limited documentation and trying to figure it out using the Javadoc documentation and the one example I found on the internet was a puzzle. I mean; it is a simple sum query. I know how to write it in SQL and in JPQL, but it seemed it would cost me half a century worth of study to write it using the CB. For example: it seems to require something called a TupleQuery. WTF? What kind of implementation details are being thrown around in the API? "S-U-M" not tuple. Yes, I know what is required underneath, but please do not bother me with it. I thought the CB was about making things typesafe, not more complex.
Anyhow, it's back to JPQL for now and I'm going to give LiquidForm another look. How to do a sum there took me a 20 seconds google, and the syntax actually makes sense.
String q = select(sum((o.getCustomer(), o.getTotalprice()))
.from(Order.class).as(o)
.groupBy(o.getCustomer())
.having(gt(o.getTotalprice(), 1000))
.toString();
One question remains: what drug was the standard committee on when they dreamt up this CriteriaBuilder monstrosity?
Tom
|
|
|
|
Re: CriteriaBuilder aborted [message #647156 is a reply to message #646289] |
Tue, 04 January 2011 19:25 |
|
EclipseLink also allows for queries to be defined using EclipseLink Expression objects and ReportQuerys, you may find these easier to use or better documented.
JPA Criteria is new, so it may take a while for examples and documentation to proliferate for them.
James : Wiki : Book : Blog : Twitter
|
|
|
Powered by
FUDForum. Page generated in 0.03011 seconds