I am upgrading the spring and hibernate jars to 4 and i am facing issues with one to many mappings.
This is my parent class Evn mapping config xml:
This is my AddressRole class config xml,
Code:
<class name="Evn" table="EVN" select-before-update="true">
<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="sequence">
<param name="sequence">EVN_ID_SEQ</param>
</generator>
</id>
<list name="addressRoles" inverse="true" fetch="subselect" lazy="false"
cascade="all">
<key>
<column name="fk_evn_Id" not-null="true" />
</key>
<index column="ROLE" type="int"></index>
<one-to-many class="AddressRole" />
</list>
<list name="histories" inverse="true" cascade="all" fetch="subselect"
lazy="true">
<key>
<column name="fk_evn_Id" not-null="true" />
</key>
<index column="ID" type="java.lang.Long"></index>
<one-to-many class="History" />
</list>
This is my History class config xml,
Code:
<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="sequence">
<param name="sequence">HISTORY_ID_SEQ</param>
</generator>
</id>
<many-to-one name="evn" class="Evn" cascade="none">
<column name="fk_evn_id" not-null="true" />
</many-to-one>
Using the below block of code i am trying to insert insert the data into DB,
Code:
Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();
try {
LOG.info("transientInstance: " + transientInstance.toString());
// transaction = session.getTransaction();
long id = (Long) session.save(transientInstance);
session.flush();
Here the all the child classes in the parent class are getting inserted successfully into DB. Then hibernate is trying to execute the update commands for one to many association but it is failing due to SQLIntegrityConstraintViolationException.
Below are the SQL query is being executed by Hibernate for one to many relationship,
Code:
2017-08-24 18:53:39,745 DEBUG [https-openssl-nio-8743-exec-5::CHY4001] spi.SqlStatementLogger -
update
EVN.ADDRESSROLE
set
ROLE=?
where
id=?
2017-08-24 18:53:39,745 DEBUG [https-openssl-nio-8743-exec-5::CHY4001] spi.SqlStatementLogger -
update
EVN.HISTORY
set
ID=?
where
ID=?
I am getting SQLIntegrityConstraintViolationException on the EVN.HISTORY table. It is trying to update the primary key value as 0 that is why i am getting SQL exception. But could not figure out how is that happening.
Same mapping is working without any issue on hibernate 3.5, but it is giving issue in hibernate 4.3.10.
Can anyone please help on this issue?