p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Java for Web Applications (http://p2p.wrox.com/forumdisplay.php?f=765)
-   -   Criterion won't compile (http://p2p.wrox.com/showthread.php?t=95420)

tzervos January 12th, 2016 06:36 AM

Criterion won't compile
 
Hi,
I'm trying to use the Criterion class from ch23 and the compiler is complaining about a few statements like this:
Code:

return b.lessThan(r.<Comparable> get(c.getPropertyName()), getComparable(c));
with the error:
"The method lessThan(Expression<? extends Y>, Expression<? extends Y>) in the type CriteriaBuilder is not applicable for the arguments (Path<Comparable>, Comparable<capture#4-of ?>)".

It looks like the getComparable(Criterion c) method is not valid with latest JPA API (I'm using 2.1:1.0.0.Final), but I'm not certain yet - still investigating.

Any ideas?


Thanks,
Tasos

tzervos January 12th, 2016 07:22 AM

I have managed to get rid of the compiler error by removing the
Code:

<?>
from this signature:
Code:

private static Comparable<?> getComparable(Criterion c)
Still not sure if this is a correct fix though - I'll test soon.

beamerblvd January 12th, 2016 10:21 AM

That's not the correct fix, because it reduces type safety in the code. But I can't figure out why this isn't working for you.

This code was tested with org.eclipse.persistence:javax.persistence:2.1.0. That's the same version you are using, but it's possible you're using a different library. Are you using org.eclipse.persistence:javax.persistence or something else? What's your full Java version? Who supplied the compiler (Oracle, Eclipse, or some other company)?

tzervos January 13th, 2016 08:31 AM

Hi, thanks for looking into this.
I am using java 1.8 (by Oracle on Mac with Eclipse Mars).
I'm also using Hibernate: 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'.

Looking at the Oracle JPA api docs, the CriteriaBuilder.lessThan signature (and the other "comparing" ones) look to match the ones from the Hibernate library I'm using: http://docs.oracle.com/javaee/6/api/...iaBuilder.html

It also looks to match the EclipseLink API also... http://www.eclipse.org/eclipselink/a...iaBuilder.html


All times are GMT -4. The time now is 11:29 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.