-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Exception during delete help me
PostPosted: Tue Jul 24, 2007 7:17 am 
Newbie

Joined: Thu Feb 01, 2007 1:57 am
Posts: 17
Location: Mumbai
Hi friends,

My application throwing this exception when we try to delete record from table i am using many-to-one relationship.
==================Exception=======================
Hibernate: select employee0_.id as id0_0_, employee0_.name as name0_0_, employee0_.age as age0_0_, employee0_.empid as empid0_0_ from Employee employee0_ where employee0_.id=?
Hibernate: delete from Employee where id=?

org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

==================My code is as:-====================

Session session = Hiberutil.getCurrentSession();
Transaction t = session.beginTransaction();
Employee p = (Employee)session.load(Employee.class,RecordID);
System.out.println("ID==="+p.getId());
session.delete(p);
session.flush();
t.commit();
session.close();\

====================HBM FILE====================
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="first.Employee" table="Employee">
<id name="id" type="int">
<generator class="increment"/>
</id>
<property name="name" type="string"/>
<property name="age" type="int"/>
<property name="empid" type="string"/>

</class>
</hibernate-mapping>

===================HBM FILE=====================
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="first.EmployeeTask" table="EmployeeTask">
<id name="id" type="int">
<generator class="increment"/>
</id>
<property name="project" type="string"/>
<property name="device" type="string"/>
<property name="deadline" type="string"/>
<property name="status" type="string"/>
<many-to-one name="parent_id" class="first.Employee" cascade="save-update,delete" />
</class>
</hibernate-mapping>



can any tell me what i missing


Thanks in adv.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 8:43 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
You delete the Employee, which has no reference to EmployeTask. The relationship from EmployeeTask to Employee is unidirectional. This means that Hibernate will not cascade your delete.

I think that you have a FK Contraint in your DB on the parent_id column of the EmployeeTask table. If you delete a person, which is referenced in this column, you'll get the mentioned exception.

_________________
Please don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.