Hi All,
I am not able to delete the parent and child entity. The details are given below.
User.hbm.file
<hibernate-mapping>
<class name="com.hibernate.pojo.User_Bank" table="USER_BANK">
<id name="id" column="ID" type="string">
<generator class="assigned"></generator>
</id>
<property name="name" column="name" type="string" />
<component name="address" class="com.hibernate.pojo.Address">
<property name="city" type="string" column="CITY" />
<property name="State" type="string" column="STATE" />
<property name="zip" type="int" column="ZIP" />
</component>
<set name="bank_details" inverse="true" cascade="all" lazy="true">
<key column="user_id" on-delete="cascade" not-null="true"/>
<one-to-many class="com.hibernate.pojo.Bank_Details"/>
</set>
</class>
</hibernate-mapping>
Bank_Details.hbm.xml
<hibernate-mapping package="com.hibernate.pojo">
<class name="com.hibernate.pojo.Bank_Details" table="BANK_DETAILS">
<id name="id">
<generator class="assigned" />
</id>
<property name="bank_name" column="BANK_NAME" type="string" />
<many-to-one name="user" column="USER_ID" class="User_Bank" cascade="all"/>
<joined-subclass table="BANK_ACCOUNT" name="com.hibernate.pojo.Bank_account">
<key column="ID" />
<property name="account_type" column="AC_TYPE" />
</joined-subclass>
<joined-subclass name="com.hibernate.pojo.Creditcard_Account" table="CREDITCARD_ACCOUNT">
<key column="ID"/>
<property name="valid_from" column="VALID_FROM" type="date"/>
<property name="valid_thru" column="VALID_THRU"/>
</joined-subclass>
</class>
</hibernate-mapping>
Deleting operation
User_Bank user = (User_Bank)session.load(User_Bank.class,
string);
session.delete(user);
The excepton I got:
Hibernate: delete from USER_BANK where ID=?
Got Excep...Could not execute
JDBC batch update
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:161)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.hibernate.util.Hibernate_Main.main(Hibernate_Main.java:53)
Caused by: java.sql.BatchUpdateException: integrity constraint violation: foreign key no action; USER_ID_FK table: BANK_DETAILS
at org.hsqldb.jdbc.JDBCPreparedStatement.executeBatch(JDBCPreparedStatement.java:1924)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
... 8 more
Please help me in solving this