-->
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.  [ 3 posts ] 
Author Message
 Post subject: delete object fail,Duplicate key or integrity constraint
PostPosted: Sun Mar 13, 2005 12:32 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

2.1.6

<class name="User" table="user">
<id
column="user_id"
name="id"
type="string"
>
<generator class="uuid.hex" />
</id>
.................................................................
<set
inverse="true"
lazy="true"
name="infoSet"
[b]cascade="all"
>
<key column="user_id" />
<one-to-many class="UserInfo" />
</set>

UserInfo.hbm.xml
Code:

<class name="UserInfo" table="user_info">
....................................................
<many-to-one
class="User"
name="user"
not-null="true"
>
<column name="user_id" />
</many-to-one>


:[/b]

public void deleteObj(final Class clazz,final Serializable objID) throws DataAccessException {
// TODO Auto-generated method stub
log.info("Delete object : "+objID);
HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
hibernateTemplate.execute(
new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Object obj=session.get(clazz,objID);
session.delete(obj);
return null;
}
});
}:


There was 1 error:
1) testDeleteObj(com.developcentry.building.test.TestBaseDAOImpl)org.springframework.dao.DataIntegrityViolationException: (Hibernate operation): data integrity violated by SQL ''; nested exception is java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Cannot delete a parent row: a foreign key constraint fails"
java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Cannot delete a parent row: a foreign key constraint fails"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2376)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:214)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:177)
at com.developcentry.building.service.BaseDAOImpl.deleteObj(BaseDAOImpl.java:55)
at com.developcentry.building.test.TestBaseDAOImpl.testDeleteObj(TestBaseDAOImpl.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at com.developcentry.building.test.TestBaseDAOImpl.main(TestBaseDAOImpl.java:32)

FAILURES!!!
Tests run: 5, Failures: 0, Errors: 1:


MySQL 3.2.3:

Hibernate: update user set user_name=?, developer_id=?, user_password=?, broker_id=? where user_id=?

INFO:
Hi everyone:

I want to delete an Object from database.My code is:
Code:

public void deleteObj(final Class clazz,final Serializable objID) throws DataAccessException {
// TODO Auto-generated method stub
log.info("Delete object : "+objID);
HibernateTemplate hibernateTemplate = this.getHibernateTemplate();
hibernateTemplate.execute(
new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Object obj=session.get(clazz,objID);
session.delete(obj);
return null;
}
});
}


But I get an exception:


Code:
java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Cannot delete a parent row: a foreign key constraint fails"


I already set cascade="all".why I can't delete user with Userinfo object?
What 's wrong with my code? Thks

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 13, 2005 3:57 am 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
I'll bet you can't delete the row because it will violate a foreign key constraint. ;)


Top
 Profile  
 
 Post subject: :(
PostPosted: Sun Mar 13, 2005 11:59 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
pkulak wrote:
I'll bet you can't delete the row because it will violate a foreign key constraint. ;)


But how to delete the parent object correctly? I already set cascade to all but it is not useful. :( How to delete it without foreign key constraint? Thks!

_________________
You are not alone...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.