【spring-boot】spring-boot使用JPAJ进行数据访问时,提示:org.hibernate.InstantiationException: No default constructor for entity: : com.springboot.jpa.entity.User

错误:org.hibernate.InstantiationException: No default constructor for entity:  : com.springboot.jpa.entity.User

解决方案:

  在相应的实体类中,创建一个无参数的构造方法即可。

@Entity
@Table(name = "tb_users")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)// 自增主键
    private Integer id;

    @Column(name = "name")
    private String name;
    @Column(name = "age")
    private Integer age;
    @Column(name = "sex")
    private String gender;
  
  //解决方案:
public User() { }

猜你喜欢

转载自www.cnblogs.com/jums/p/11304827.html