Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » CriteriaBuilder aborted
CriteriaBuilder aborted [message #646289] Thu, 23 December 2010 03:00 Go to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
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 #646375 is a reply to message #646289] Thu, 23 December 2010 10:07 Go to previous messageGo to next message
Rich MacDonald is currently offline Rich MacDonald
Messages: 18
Registered: December 2010
Junior Member
To each his own. Nothing wrong with CriteriaBuilder for those who know how to use it. I recommend the book "Pro JPA 2". But if you're unwilling to figure out what a TupleQuery is, I think you have made the correct decision to stay with what you already know.
Re: CriteriaBuilder aborted [message #647156 is a reply to message #646289] Tue, 04 January 2011 14:25 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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
Previous Topic:How can I query all past versions of an object with eclipselink?..
Next Topic:quoted identifiers
Goto Forum:
  


Current Time: Sat Aug 23 05:48:15 EDT 2014

Powered by FUDForum. Page generated in 0.08693 seconds