开发者

JPA Hibernate Help!

开发者 https://www.devze.com 2023-02-23 05:17 出处:网络
I have just studied about JPA. And I had created a simple program which return the query \"SELECT ...\".

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号