【发布时间】:2013-10-05 10:29:56
【问题描述】:
我在 Hibernate 中使用 Spring Data JPA。
我有一个复合键映射到数据库表的类。
当我使用 JPARepository 扩展接口对象执行保存操作时,我在控制台中看到以下日志:
Hibernate: select rolefuncti0_.functionalityId as function1_4_0_, rolefuncti0_.roleId as roleId2_4_0_ from RoleFunctionality_Mapping rolefuncti0_ where rolefuncti0_.functionalityId=? and rolefuncti0_.roleId=?
Hibernate: insert into RoleFunctionality_Mapping (functionalityId, roleId) values (?, ?)
这是我用相同的数据重复操作时看到的:
Hibernate: select rolefuncti0_.functionalityId as function1_4_0_, rolefuncti0_.roleId as roleId2_4_0_ from RoleFunctionality_Mapping rolefuncti0_ where rolefuncti0_.functionalityId=? and rolefuncti0_.roleId=?
看来Spring Data首先检查数据库中是否存在Key,然后继续执行插入。
应该有办法捕获hibernate找到的信息(数据库条目/密钥存在于数据库中)?我们如何检查?
【问题讨论】:
标签: java mysql spring hibernate spring-data-jpa