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?
source share