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