I have just studied about JPA. And I had created a simple program which return the query "SELECT ...". Unfortunately, I always get an exception like
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to application.Model
at application.Main.main(Main.java:33)
I can't understand why, yet I tried using String.valueOf(...) to the line and returns the same exception.
开发者_开发知识库All of the codes are present here.
Instead of
Query query = entityManager.createNativeQuery("SELECT * FROM person");
List<Model> models = query.getResultList();
You can try -
List<Model> models = entityManager.createQuery("from Model",Model.class).getResultList();
I don't see any purpose for using native query here.
精彩评论