如果我们的方法标有@Transactional(readOnly = true) 注释,那么我们不能在其中(以及在它调用的那些方法中)使用CREAT、UPDATE、DELETE 操作。但是有了退出方法后的数据本身,我们还能做些什么呢?这是正确的?
Igor Gorbunov
Asked:
2020-09-10 00:31:23 +0800 CST
如果我删除这样的实体:
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;
//геттеры, сеттеры
}