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

前端 未结 4 2977
陌清茗
陌清茗 2021-01-04 06:46

User declaration:

@Entity
public class User {
    @Id
    @GeneratedValue
    private Integer id;
    ....

Pattern declaration:

<         


        
相关标签:
4条回答
  • 2021-01-04 07:23

    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.

    0 讨论(0)
  • 2021-01-04 07:26

    i think maybe your annotation should be

    @ManyToOne(TargetEntity=....class)

    0 讨论(0)
  • 2021-01-04 07:28

    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.

    0 讨论(0)
  • 2021-01-04 07:30

    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

    0 讨论(0)
提交回复
热议问题