小编red*_*ist的帖子

Spring JPA存储库删除方法不起作用

我无法让 Spring JPA 使用 jpa 存储库删除方法删除 bar 实体。
谁能看出问题出在哪里吗?

不起作用:

barRepository.delete(bar.id);
Run Code Online (Sandbox Code Playgroud)

Jpa 存储库:

public interface BarRepository extends JpaRepository<Bar, Integer>
Run Code Online (Sandbox Code Playgroud)

Hibernate 实体映射(仅相关部分):

@Entity(name = "foo")

@OneToMany(fetch = FetchType.EAGER, mappedBy = "foo", cascade = CascadeType.ALL, orphanRemoval = true)
@Fetch(FetchMode.SELECT)
private List<Bar> bars = new ArrayList<>();

@Entity(name = "bar")

@ManyToOne(optional = false)
@JoinColumn(name = "foo_id")
@Fetch(FetchMode.SELECT)
private Foo      foo;
Run Code Online (Sandbox Code Playgroud)

编辑:具有最小可重现示例的 git repo。 HibernateDeleteApplicationTests.java包含测试用例。

https://github.com/matijaivanus/hibernate-delete-problem

java spring hibernate jpa

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

hibernate ×1

java ×1

jpa ×1

spring ×1