EclipseLink Error: Exception Description: Missing handle for class

I just want to make a simple custom request with EclipseLink, but I can't get it to work

@Repository("CarsRepository") public class JpaCarsRepository { @PersistenceContext private EntityManager em; public List<Car> getCars(){ Query q=em.createNativeQuery("SELECT id,name_car FROM CARS",Car.class); List<Car> results=q.getResultList(); 

My 'Car' class is defined as @Entity. (my persistence.xml has only basic connection parameters). I get the "Missing Descriptor" error for the "Car" class.

Why is this happening? I saw a similar question that did not help me.

Second question:

If I do not specify the second parameter of the createNativeQuery (Car.class) function, it returns a list of objects, so I see that the value of result.get (0) is [1 car]. I can iterate over a list of objects. Therefore, if

 Object o=results.get(0) 

I could create Car objects manually, but I don’t know how to get the first value of an object, if I type o [0] to get the value of 1 object (which is [1 car]), I get the following error: type of expression must be array type but allowed for an object

How can I access each value of an object?

+4
source share
1 answer

He does not consider the Car as an entity, it seems that it is not scanned. Does listing include your entity inside a class element in persistence.xml?

The second attempt returns a list of arrays of objects. To access the values, you must first wrap one row of the result set into an array of objects:

 Object[] o=results.get(0) //types below are just guessed: Integer id = o[0]; String name = o[1]; 
+2
source

Source: https://habr.com/ru/post/1391146/


All Articles