【发布时间】:2018-01-26 14:50:39
【问题描述】:
我看过这些链接
- How to use JPA Query to insert data into db? 使用 nativeQuery=true
- How to insert into db in spring-data? 建议使用内置的保存方法(还有一个 saveAndFulsh() 方法)
我的例子如下:
Person 是一个简单的实体,包含 3 个字段“Long id、String name、Integer age”,并且映射到对应的 Person 表,每个表包含 3 个列)
@Repository
public interface DualRepository extends JpaRepository<Dual,Long> {
@Modifying
@Query(? - what goes here - ?)
public int modifyingQueryInsertPerson(@Param("id")Long id, @Param("name")String name, @Param("age")Integer age);
}
有没有办法只使用@Query & @Modifying 进行插入(即不使用本机 SQL 查询 & nativeQuery=true,或者,save(),或者,saveAndFlush()?
【问题讨论】:
标签: hibernate insert spring-data spring-data-jpa