如何在oneToMany关系中坚持子实体?Spring JPA + Hibernate:OneToMany双向持久
@Entity
public class Payment implements Serializable {
@ManyToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
@JoinColumn(name = "registration", nullable = false)
private Registration registration;
}
@Entity
public class Registration implements Serializable {
@OneToMany(mappedBy="registration", cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
private List<Payment> payment;
}
在登记的创建,如果登记列不在支付表可为空:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: 列 '注册' 不能为空
但是,如果注册为空,则会创建付款,但注册列为空:
直到发生异常并且执行“HH000010:批量释放时仍包含JDBC语句”。
请你能帮帮我,禁用Hibernate批处理或明白是什么错误?
我在使用带有CrudRepository的spring boot-jpa。通常不需要指定孩子坚持。而就我而言,孩子是支付,必须坚持创建注册 – Mezoo