Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NamedNativeQuery (can not cast to class)
NamedNativeQuery [message #531708] Wed, 05 May 2010 16:54 Go to previous message
Larry  is currently offline Larry
Messages: 30
Registered: December 2009
Member
I have the following query:

@NamedNativeQuery(
name="getCar",
query="select * from car where id = 10 and type= 1")


I did setup a Car Entity that runs fine using the following code:
Car car= em.find(Car .class, new Car Pk(101000,1));

When I execute the following:
Car c = (Car ) em.createNamedQuery("getCar").getSingleResult();

I get the following error stack:

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.jimbo.jpa.Car
at Driver.doTest4(Driver.java:66)
at Driver.run(Driver.java:34)
at Driver.main(Driver.java:83)


Now, if I change my query buy adding a resultClass:
@NamedNativeQuery(
name="getCar",
query="select * from car where id = 10 and type= 1",
resultClass=Car.class)


I then get the following stack error:
Exception Description: The primary key read from the row [DatabaseRecord(
=> 10
=> 1
car.size => 10000
=> null)] during the execution of the query was detected to be null. Primary keys must not contain null.



Can someone tell me what I'm doing wrong? It seems in the last attempt using resultClass, that all fields are being treated as part of the primary key. I have the CarPk setup with the id and type as the ids.

Thanks
 
Read Message
Read Message
Read Message
Read Message
Previous Topic:Filtering a OneToMany relationship
Next Topic:Delay betwen persist and find of a relationship
Goto Forum:
  


Current Time: Fri May 24 02:25:02 EDT 2013

Powered by FUDForum. Page generated in 0.01648 seconds