我得到以下期望:
org.springframework.orm.jpa.JpaSystemException: Batch update returned unexpected row count from update [0]; actual row count: 3; expected: 1; nested exception is
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 3; expected: 1
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:314) ~[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE]
当我尝试级联删除与另一个实体(Dog)具有一对多关系的实体(Kennel)时会发生这种情况。
删除代码(使用CRUD存储库删除方法):
kennelRepository.delete(kennelEntity);
狗窝实体(家长):
@Entity
@Table(name = "KENNEL")
public class Kennel implements Serializable
{
//other fields and getters/setters
@OneToMany(mappedBy = "kennel", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private List<Dog> dogList = new LinkedList<Dog>();
狗实体(儿童):
@Entity
@Table(name = "DOG")
public class Dog implements Serializable
{
//other fields and getters/setters
@ManyToOne
@JoinColumns({
@JoinColumn(name = "KENNEL_ID", referencedColumnName = "KENNEL_ID"),
@JoinColumn(name = "KENNEL_NUMBER", referencedColumnName = "KENNEL_NUMBER")
})
private Kennel kennel;
可能导致这种情况的原因是什么?我几乎可以肯定映射是正确的吗?
我也尝试将抓取类型从LAZY
更改为EAGER
,但错误相同。
答案 0 :(得分:0)
1.如果已经从后端数据库手动删除了实体并且hibernate试图再次将其删除,则会发生这种情况。
2.只需检查是否没有其他进程删除记录