Can not set java.lang.Integer field to java.lang.Integer

拈花ヽ惹草 提交于 2019-11-30 17:31:08

What happens if you change your HQL query to from UserPattern where user.id = :user_id and pattern.id = :pattern_id?

I think Hibernate is confusing objects and ID fields.

You need to modify your query as follows:

from UserPattern where user.id = :user_id and pattern.id = :pattern_id

In your query, you are trying to match a User object with an Integer object.

If your field name is "id", your getter and setter methods should be named

public Integer getId(){return id;}
public void setId(Integer id){this.id = id};

If your are using Eclipse, generate the getter/setter by right click -> Source -> Generate Getters and Setters...

Make sure your getters and setter are public. Also you should add @Table-Annotation to all your Entities

i think maybe your annotation should be

@ManyToOne(TargetEntity=....class)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!