线程“主”中的异常javax.persistence.PersistenceException:org.hibernate.InstantiationException:实体没有默认构造函数:

时间:2019-03-17 15:12:50

标签: java hibernate

嗨,我是新来的冬眠者。每当我尝试从MySQL 5.5检索数据时,都会抛出异常 Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.InstantiationException: No default constructor for entity:

但是当我尝试将数据保存在sql表中时,它可以正常工作。 我也找到了这个problem的解决方案,但仍然显示相同的错误。

1 个答案:

答案 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;
    }

   }