0

I have 2 entities: Request and Invoice. (One to many) How can I get result object:

public class TestRequest {
    private Long idRequest;
    private List<Long> idInvoices;
}

Follow code:

Query query = entityManager.createNativeQuery("Select r.REQUEST_ID idRequest, i.INVOICE_ID idInvoices From WAROWN.T_REQUEST r right join WAROWN.T_INVOICE i on r.REQUESTED_ID = i.CHECK_HISTORY_ID", TestRequest.class);

has exception: There was an error packing the projection and/or aggregate results of the query into result type "class com.mypackage.TestRequest".

  • Can you post further exception details please ? – Shailendra Oct 10 '13 at 10:28
  • org.apache.openjpa.persistence.ArgumentException: There was an error packing the projection and/or aggregate results of the query into result type "class com.TestRequest". See the nested Throwable exception for details. FailedObject: Select r.REQUEST_ID idR, i.INVOICE_ID invoice From WAROWN.T_REQUEST r right join WAROWN.T_INVOICE i on r.REQUESTED_ID = i.CHECK_HISTORY_ID [java.lang.String] at org.apache.openjpa.kernel.ResultPacker.packUserType(ResultPacker.java at org.apache.openjpa.kernel.ResultPacker.pack(ResultPacker.java .... – Евгений Цацкин Oct 10 '13 at 10:36
  • Caused by: java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.openjpa.kernel.ResultPacker.packUserType(ResultPacker.java:280) – Евгений Цацкин Oct 10 '13 at 10:37
  • The problem is that your resultset from the native query will contain String,String and your TestRequest is a simple POJO and not an entity. Your are instructing Open JPA to convert String into List which it is failing. You might need to make this class an Entity. As you are using Open JPA, you can have a look into the docs to see how to do this as I am not aware of Open JPA. – Shailendra Oct 10 '13 at 11:22

0 Answers0