Mysql JPA持久化方法

Mysql JPA持久化方法,mysql,jpa,Mysql,Jpa,如何使用JPA和hibernate将数据插入表中,仅用于表的某些列? 例如,在employee表中,我只想插入主键,rest all应该为空。我应该如何使用JPA编写查询?您必须首先验证所有字段都可以为空 其次,必须对表示表的JPA实体进行建模 第三,必须注入entityManager并调用persist()方法 代码如下所示: 服务: Employee emp = new Employee(); // if you annotate the id as autogenerated or seq

如何使用JPA和hibernate将数据插入表中,仅用于表的某些列?
例如,在employee表中,我只想插入主键,rest all应该为空。我应该如何使用JPA编写查询?

您必须首先验证所有字段都可以为空

其次,必须对表示表的JPA实体进行建模

第三,必须注入entityManager并调用persist()方法

代码如下所示:

服务:

Employee emp = new Employee();
// if you annotate the id as autogenerated or sequence, 
// you shouldn't set the id property, if it's manual you should do 
// emp.setId (1)
道:

entityManager.persist(emp)