Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] NEW() operation in JPQL query does not locate the constructor correctly when generics are used.

The NEW() function assumes the type on the constructor matches exactly the
returned values.

But I agree, it should be smart enough to find the constructor.  We should
search all constructors that match the number of arguments and find the best
match if an exact match is not find.  Please log a bug for this.



Pinaki Poddar wrote:
> 
> Hi,
>   NEW() operation in JPQL query does not locate the constructor correctly
> when generics are used.
> 
> Here is JPQL query using a NEW() operator
>         "select new openbook.util.Range(MIN(b.price), MAX(b.price)) from
> Book b";
> 
> where openbook.util.Range has the following constructor
>   public class Range<N extends Number>
>       public Range(N min, N max)
> 
> And Book.price is declared as
>       private double price;
> 
> 
> ends up with following stacktrace. Works if Range declares a constructor
> with two Object type arguments (and an ugly cast:)
>  
>      [java] Exception [EclipseLink-6137] (Eclipse Persistence Services -
> 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.QueryException
>      [java] Exception Description: An Exception was thrown while executing
> a ReportQuery with a constructor expression:
> java.lang.NoSuchMethodException: openbook.util.Range.<init>(
> java.lang.Object, java.lang.Object)
>      [java] Query: ReportQuery(referenceClass=Book jpql="select new
> openbook.util.Range(MIN(b.price), MAX(b.price)) from Book b")
>      [java]     at
> org.eclipse.persistence.exceptions.QueryException.exceptionWhileUsingConstructorExpression(QueryException.java:472)
>      [java]     at
> org.eclipse.persistence.queries.ConstructorReportItem.initialize(ConstructorReportItem.java:187)
>      [java]     at
> org.eclipse.persistence.queries.ReportQuery.prepare(ReportQuery.java:1026)
>      [java]     at
> org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:464)
>      [java]     at
> org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:732)
>      [java]     at
> org.eclipse.persistence.queries.DatabaseQuery.prepareCall(DatabaseQuery.java:1577)
>      [java]     at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:240)
>      [java]     at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:173)
>      [java]     at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:125)
>      [java]     at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:109)
>      [java]     at
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1326)
>      [java]     at
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1348)
>      [java]     at openbook.server.OpenBookService.querySingle(Unknown
> Source)
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/NEW%28%29-operation-in-JPQL-query-does-not-locate-the-constructor-correctly-when-generics-are-used.-tp27409986p27421802.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top