Tag: orphan

即使在一对多关系中使用orphanRemoval = true,孤儿仍保留在数据库中(JPA / Hibernate)

@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Table(name = “company_policies”) @DiscriminatorColumn(name = “rule_name”) public abstract class AbstractPolicyRule implements Serializable { @Transient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; private String value; … } _ @Entity public class Category implements Serializable { @Transient private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long […]

Hibernate在更新集合时删除孤立

我发现从Hibernate中的集合中删除时不会删除孤立记录。 我必须做一些简单的错误,(这是Hibernate-101!),但我找不到它.. 鉴于以下内容: public class Book { @ManyToOne @NotNull Author author; } public class Author { @OneToMany(cascade={CascadeType.ALL}) List books; } 以下更新代码: Author author = authorDAO.get(1); Book book = author.getBooks().get(0); author.getBooks().remove(0); authorDAO.update(author); AuthorDAO代码段: @Override public void update(T entity) { getSession().update(entity); } 以下测试失败: Author author = author.get(1); assertEquals(0,author.getBooks().size()); // Passes Book dbBook = bookDAO.get(book.getId()) assertNull(dbBook); // Fail! […]