Hibernate:坚持@OneToMany 无一例外地卡住(其中子实体插入未在 showsql 中打印)
Hibernate: Persisting @OneToMany Stuck with no exception (where child entity insert is not getting printed in showsql)
主要实体:
CustomerAgreement {
@OneToMany(mappedBy = "customerAgreement", orphanRemoval = true, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
private List<CustomerAgreementPeriod> agreementPeriods;
}
引用 ManyToOne 的实体:
public class CustomerAgreementPeriod implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "CustomerAgreementPeriodSeq", sequenceName = "CUST_AGT_PERIOD_SEQ")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "CustomerAgreementPeriodSeq")
@Column(name = "ID")
private Long id;
@ManyToOne
@JoinColumn(name = "CUSTID")
private CustomerAgreement customerAgreement;
.
.
}
主要代码:
CustomerAgreement cAgreement = new CustomerAgreement();
cAgreement.setId(32121212l);
cAgreement.setName("Kiki");;
cAgreement.setCustomerId("140");
List<CustomerAgreementPeriod> cap = new ArrayList<>();
CustomerAgreementPeriod capy = new CustomerAgreementPeriod();
capy.setPid("1");
capy.setValidFrom(new Date());
capy.setValidTo(new Date());
capy.setCustomerAgreement(cAgreement);
CustomerAgreementPeriod capy2 = new CustomerAgreementPeriod();
capy2.setPid("2");
capy2.setValidFrom(new Date());
capy2.setValidTo(new Date());
capy2.setCustomerAgreement(cAgreement);
cap.add(capy);
cap.add(capy2);
cAgreement.setAgreementPeriods(cap);
em.getTransaction().begin();
em.persist(cAgreement);
em.getTransaction().commit();
错误:
没有显示错误,但只有一个向main的插入查询,如下所示:
Hibernate:
select
CUST_AGT_PERIOD_SEQ.nextval
from
dual
Hibernate:
select
CUST_AGT_PERIOD_SEQ.nextval
from
dual
Hibernate:
insert
into
CIM_SNOW_CUST_AGREEMENT_TAB
values
似乎线程卡在某处可能是无限循环或其他问题。
任何人都可以建议为什么会发生这种情况以及如何解决这个问题吗?
这个问题是我这边的。
但这很奇怪,Hibernate 没有抛出任何异常并保持 运行。
问题:根据上述实体,table 中不存在字段 ID 和 CUSTID。
我认为我们应该始终在 persistance.xml 中添加验证属性以在部署时进行验证
主要实体:
CustomerAgreement {
@OneToMany(mappedBy = "customerAgreement", orphanRemoval = true, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
private List<CustomerAgreementPeriod> agreementPeriods;
}
引用 ManyToOne 的实体:
public class CustomerAgreementPeriod implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "CustomerAgreementPeriodSeq", sequenceName = "CUST_AGT_PERIOD_SEQ")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "CustomerAgreementPeriodSeq")
@Column(name = "ID")
private Long id;
@ManyToOne
@JoinColumn(name = "CUSTID")
private CustomerAgreement customerAgreement;
.
.
}
主要代码:
CustomerAgreement cAgreement = new CustomerAgreement();
cAgreement.setId(32121212l);
cAgreement.setName("Kiki");;
cAgreement.setCustomerId("140");
List<CustomerAgreementPeriod> cap = new ArrayList<>();
CustomerAgreementPeriod capy = new CustomerAgreementPeriod();
capy.setPid("1");
capy.setValidFrom(new Date());
capy.setValidTo(new Date());
capy.setCustomerAgreement(cAgreement);
CustomerAgreementPeriod capy2 = new CustomerAgreementPeriod();
capy2.setPid("2");
capy2.setValidFrom(new Date());
capy2.setValidTo(new Date());
capy2.setCustomerAgreement(cAgreement);
cap.add(capy);
cap.add(capy2);
cAgreement.setAgreementPeriods(cap);
em.getTransaction().begin();
em.persist(cAgreement);
em.getTransaction().commit();
错误:
没有显示错误,但只有一个向main的插入查询,如下所示:
Hibernate:
select
CUST_AGT_PERIOD_SEQ.nextval
from
dual
Hibernate:
select
CUST_AGT_PERIOD_SEQ.nextval
from
dual
Hibernate:
insert
into
CIM_SNOW_CUST_AGREEMENT_TAB
values
似乎线程卡在某处可能是无限循环或其他问题。
任何人都可以建议为什么会发生这种情况以及如何解决这个问题吗?
这个问题是我这边的。
但这很奇怪,Hibernate 没有抛出任何异常并保持 运行。
问题:根据上述实体,table 中不存在字段 ID 和 CUSTID。
我认为我们应该始终在 persistance.xml 中添加验证属性以在部署时进行验证