如何使用JPA和hibernate将数据插入表中的某些列?例如,在employee表中,我只想插入主键,而rest all应该为空。我应该如何使用JPA编写查询?
发布于 2020-03-10 23:10:37
您必须首先验证所有字段都可以为空。
其次,您必须对表示表的JPA实体进行建模。
第三,必须注入持久化并调用entityManager ()方法。
代码将如下所示:
服务:
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)DAO:
entityManager.persist(emp)https://stackoverflow.com/questions/60558758
复制相似问题