嗨,我是新来的冬眠者。每当我尝试从MySQL 5.5检索数据时,都会抛出异常
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.InstantiationException: No default constructor for entity:
但是当我尝试将数据保存在sql表中时,它可以正常工作。 我也找到了这个problem的解决方案,但仍然显示相同的错误。
答案 0 :(得分:1)
确保实体中没有参数构造器
@Entity
@Table(name = "employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
@Column(name="age")
private Integer age;
// A default constructor, one without agruments
public Employee() {
}
// A constructor with agruments
public Employee(Integer id, String name, Integer age) {
this.id = id;
this.name = name;
this.age = age;
}
}