I want just an response to a really specific question:
Customer c =(Customer) manager.createQuery("SELECT c FROM Customer c").getResultList().get(0);
This code works due to using the Java Persistence Query Language.
Customer c = (Customer) manager.createNativeQuery("SELECT * FROM Customer LIMIT 1").getSingleResult();
Using similar code along with a native query casting to some
Customer will not work, a
ClassCastException is going to be elevated.
Leading towards the question: Can you really create objects as is a result of a native query using SQL?
I believe you are able to, have a look in the documentation for createNativeQuery (the main one with 2 params Im getting challenge with the hyperlink)
just pass the course you would like in to the createNativeQuery call....
I clearly haven't seen that certain. It appears to become a far easier way than learning JQL.
There is however another problem that could be a possible pitfall: In some instances you have to enter area names in upper situation letters.
I can not make sure, but you may be encountering a situation sensitivity problem quite common when utilizing native queries. JPA defaults area names to upper situation, and when you're utilizing a database that could return fieldnames as lower situation, because Java string evaluations are situation sensitive the area is probably not found. This may cause the resultset to come back null if this searches for the worthiness for "ID".
Interesting quick answer.