CriteriaBulder [message #553703] |
Wed, 18 August 2010 10:14  |
Eclipse User |
|
|
|
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 14:29  |
Eclipse User |
|
|
|
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 11:49  |
Eclipse User |
|
|
|
> 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
|
|
|
Powered by
FUDForum. Page generated in 0.04856 seconds