Prashant-
Is the query syntax not correct or Am I missing any configuration?
The syntax looks OK to me, and our tests of the "select new"
operation are passing OK.
My only guess is that the parameter types of your constructor do not
exactly match the values you are passing in. Can you post the
signature for the constructor as well as the field types for each of
the fields? Does the constructor match the types mentioned in the
error: "long, class java.lang.String, class java.lang.String, class
com.sample.entity.AccountType, class java.math.BigDecimal"
Note that automatic type conversions or wrapping/unwrapping doesn't
take place when evaluating a constructor. E.g., "select new SomeClass
(x.someIntField) as x" will not work if the constructor for SomeClass
takes a double.
On Jul 23, 2007, at 11:30 PM, Prashant Bhat wrote:
Hi,
I've an Account entity with a default constructor and another with
parameters as shown below.
With this query, I'm getting the following exception,(although the
constructor is available)
SELECT NEW com.sample.entity.Account(x.id, x.accountNumber, x.name,
x.accountType, x.currentBalance) FROM Account AS x
<0.0.0 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException:
Result type "class com.sample.entity.Account" does not have any public
fields or setter methods for the projection or aggregate result
element
"jpqlalias1", nor does it have a generic put(Object,Object) method
that can
be used, nor does it have a public constructor that takes the types
[long,
class java.lang.String, class java.lang.String, class
com.sample.entity.AccountType, class java.math.BigDecimal].
at org.apache.openjpa.kernel.ResultPacker.<init>
(ResultPacker.java:139)
at org.apache.openjpa.kernel.ResultPacker.<init>
(ResultPacker.java:102)
at org.apache.openjpa.kernel.QueryImpl.getResultPacker
(QueryImpl.java
:1255)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:
1205)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:989)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:798)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:768)
at org.apache.openjpa.kernel.DelegatingQuery.execute(
DelegatingQuery.java:533)
at org.apache.openjpa.persistence.QueryImpl.execute
(QueryImpl.java:227)
at org.apache.openjpa.persistence.QueryImpl.getResultList
(QueryImpl.java
:269)
at org.springframework.orm.jpa.JpaTemplate$9.doInJpa
(JpaTemplate.java
:313)
at org.springframework.orm.jpa.JpaTemplate.execute
(JpaTemplate.java:191)
at org.springframework.orm.jpa.JpaTemplate.executeFind
(JpaTemplate.java
:158)
at org.springframework.orm.jpa.JpaTemplate.find(JpaTemplate.java:
305)
Is the query syntax not correct or Am I missing any configuration?
Thanks,
Prashant
PS. I'm using latest snapshots of OpenJPA with Spring-2.0.6 and H2
Database