Entity Main:
CustomerAgreement {
@OneToMany(mappedBy = "customerAgreement", orphanRemoval = true, fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
private List<CustomerAgreementPeriod> agreementPeriods;
}
Entity where ManyToOne is referred:
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;
.
.
}
Main Code:
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();
Error:
No error is shown but only one insert query to main is shown as below:
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
It appears thread stuck somewhere may be infinite loop or something.
Could any one suggest why this is happening and how to fix this?
This issue was on my side.
But this is strange that Hibernate does not throw any exception and keep on running.
Issue: The field ID and CUSTID do not exists in table as per above mentioned entities.
I think we should always add validate proeprty in persistance.xml to validate at deployment