JPA: Differences between JQL and SQL

I need just an answer to a very specific question:

For example:

Customer c =(Customer) manager.createQuery("SELECT c FROM Customer c").getResultList().get(0);

This code works because of the use of the Java Persistence Query Language.

Customer c = (Customer) manager.createNativeQuery("SELECT * FROM Customer LIMIT 1").getSingleResult();

Using similar code and a native query casting to a Customer won't work, a ClassCastException will be raised.

That leads to the question: Is it possible to create objects as results from a native query using SQL?

Answers


I think you can, take a look at the documentation for createNativeQuery (the one with 2 params; Im having trouble with the link)

just pass the class you want into the createNativeQuery call....


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.