如果我删除这样的实体:
public void remove(Case lawsuit) {
Case c = entityManager.find(Case.class, lawsuit.getId());
entityManager.remove(c);
}
那么它不会被删除,但如果是这样的话:
public void remove(Case lawsuit) {
Case c = entityManager.find(Case.class, lawsuit.getId());
entityManager.getTransaction().begin();
entityManager.remove(c);
entityManager.getTransaction().commit();
}
它通常被删除。为什么这是我可以删除的唯一方法?这是实体本身:
@Entity
@Table(name = "cases")
public class Case {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String caseNumber;
private String dataI;
private String dataII;
private String dataIII;
@ManyToOne
@JoinColumn(name = "judgeID")
private Judge judge;
@ManyToOne
@JoinColumn(name = "lawyerID")
private Lawyer lawyer;
@ManyToOne
@JoinColumn(name = "clientID")
private Client client;
@Enumerated(value = EnumType.ORDINAL)
private CaseStatus statusI;
@Enumerated(value = EnumType.ORDINAL)
private CaseStatus statusII;
@Enumerated(value = EnumType.ORDINAL)
private CaseStatus statusIII;
private String document;
//геттеры, сеттеры
}
JPA 2.1 规范的第 3.2.3 节中描述了删除如何影响处于每种可能状态的实体