Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » CriteriaBulder
CriteriaBulder [message #553703] Wed, 18 August 2010 14:14 Go to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 807
Registered: July 2009
Senior Member
I'm getting my feet wet with the new JPA 2.0 query builder. So far I'm able to run a simple condition (string is value), but when I want to use GregorianCalendar I get troubles with generics.

In the query below the two conditions on BUYDATE do not compile:

CriteriaBuilder lCriteriaBuilder = lEntityManager.getCriteriaBuilder();
CriteriaQuery<Buyorder> lCriteriaQuery = lCriteriaBuilder.createQuery(Buyorder.class);
Root<Buyorder> lBuyorderRoot = lCriteriaQuery.from(Buyorder.class);
lCriteriaQuery = lCriteriaQuery.select(lBuyorderRoot).where(
lCriteriaBuilder.and(
lCriteriaBuilder.equal(lBuyorderRoot.get(Buyorder.RELATION_F IELD_ID), relation),
lCriteriaBuilder.greaterThanOrEqualTo(lBuyorderRoot.get(Buyo rder.BUYDATE_FIELD_ID), from),
lCriteriaBuilder.lessThanOrEqualTo(lBuyorderRoot.get(Buyorde r.BUYDATE_FIELD_ID), upToAndIncluding)
)
);

Eclipse says:

Bound mismatch: The generic method greaterThanOrEqualTo(Expression<? extends Y>, Expression<? extends Y>) of type CriteriaBuilder is not applicable for the arguments (Path<Object>, GregorianCalendar).
The inferred type Object is not a valid substitute for the bounded parameter <Y extends Comparable<? super Y>>

Tom

PS: I have not gotten to the point where I have Maven generate the meta classes, one step at a time, but because I have ID's constants in my classes (Buyorder.BUYDATE_FIELD_ID) I'm compiler checkable already.
Re: CriteriaBulder [message #554250 is a reply to message #553703] Fri, 20 August 2010 18:29 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello Tom,

I find type safety to be a bit of a pain at times. The problem here is because the expression returned from lBuyorderRoot.get(Buyo rder.BUYDATE_FIELD_ID) doesn't have a type; the generic expression types need to inherit/implement the Comparable interface. You will need to cast it as the type you expect, something like:
lBuyorderRoot.get(Buyo rder.BUYDATE_FIELD_ID).as(GregorianCalendar.class)

Best Regards,
Chris
Re: CriteriaBulder [message #554271 is a reply to message #554250] Fri, 20 August 2010 15:49 Go to previous message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 807
Registered: July 2009
Senior Member
> I find type safety to be a bit of a pain at times. The problem here is because the expression returned from lBuyorderRoot.get(Buyo rder.BUYDATE_FIELD_ID) doesn't have a type; the generic expression types need to inherit/implement the Comparable interface. You will need to cast it as the type you expect, something like:
> lBuyorderRoot.get(Buyo rder.BUYDATE_FIELD_ID).as(GregorianCalendar.class)

Thank you Chris, I'll give it a spin monday.
I find very little documentation on this; it's all just the basics.

Tom
Previous Topic:PersistenceProvider Service not starting at first time
Next Topic:Querying archived entities
Goto Forum:
  


Current Time: Mon Nov 24 14:06:05 GMT 2014

Powered by FUDForum. Page generated in 0.16023 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software