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.  [ 1 post ] 
Author Message
 Post subject: referential integrity violation deleting
PostPosted: Wed Sep 08, 2004 5:23 pm 
Newbie

Joined: Thu Oct 30, 2003 5:38 pm
Posts: 9
Location: CA
I'm getting a referential integrity violation error when attempting to delete an entry on the many side of a many-to-one relationship.
The full error text is "fk1625798e3306904b referential integrity violation - key in message_multi_strings still referenced from sign_messages"

A summary of the mapping is:
ModelObject is top-level abstract containing primarily the UinqueID.
Direct sub-classes are MessageMultiString and SignMessage where that latter has a many-to-one relationship to the former.
And SignMessage has a sub-class VmsSignMessage.

What is desired:
If an attempt is made to delete MessageMultiString we *do* want a referential integrity error to propagate.
However, if a SignMessage (or VmsSignMessage) is deleted we do *not* want a referential integrity violation to occur.

What is happening is a referential integrity error when a VmsSignMessage instance is being deleted.

I have tried using cascade="all", cascade="save-update", and cascade="none" in the many-to-one relationship, but all have behaved the same.

Can someone point out the error of my ways?
I would hate to have to clear out the many-to-one reference prior to deleting the child instance, but right now I don't see any other way.


[b]Hibernate version: 2.1.2[/b]


[b]Mapping documents:[/b]

/**
* @hibernate.class table="objects"
*/
public abstract class ModelObject implements Traceable {
protected UUID id;
/**
* @hibernate.id type="com.transdyn.dynac.framework.hibernate.UUIDType"
* generator-class="com.transdyn.dynac.framework.hibernate.UUIDGenerator"
* @hibernate.column name="object_id" sql-type="char(36)"
*/
public UUID getId() {
return id;
}
}

/**
* @hibernate.joined-subclass table="sign_messages"
* @hibernate.joined-subclass-key
* @hibernate.joined-subclass-key-column name="sign_message_id" sql-type="char(36)"
*/
public class SignMessage extends ModelObject {
protected MessageMultiString _message = null;
/**
* @hibernate.many-to-one class="com.transdyn.dynac.device.signs.messages.MessageMultiString"
* cascade="none"
* @hibernate.column name="message_multi_string_id" sql-type="char(36)"
*/
public MessageMultiString getMessage() {
return _message;
}
}

/**
* @hibernate.joined-subclass table="vms_sign_messages"
* @hibernate.joined-subclass-key
* @hibernate.joined-subclass-key-column name="vms_sign_message_id" sql-type="char(36)"
*/
public class VmsSignMessage extends SignMessage {
private int _referenceNumber;
/**
* @hibernate.property column="reference_number"
*/
public int getReferenceNumber() {
return _referenceNumber;
}
}

/**
* @hibernate.joined-subclass table="message_multi_strings"
* @hibernate.joined-subclass-key
* @hibernate.joined-subclass-key-column name="message_multi_string_id" sql-type="char(36)"
*/
public class MessageMultiString extends ModelObject {
private String _description = null;
/**
* @hibernate.property column="description" type="string" length="80"
*/
public String getDescription() {
return _description;
}
}


[b]Code between sessionFactory.openSession() and session.close(): Spring 1.0.1[/b]


[b]Full stack trace of any exception that occurs:[/b]
[junit] testDeleteVmsSignMessages
[junit] (JDBCExceptionReporter.java:38) WARN - SQL Error: 0, SQLState: null
[junit] (JDBCExceptionReporter.java:46) ERROR - ERROR: fk1625798e3306904b referential integrity violation - key in message_multi_strings still referenced from sign_messages

[junit] (JDBCExceptionReporter.java:38) WARN - SQL Error: 0, SQLState: null
[junit] (JDBCExceptionReporter.java:46) ERROR - ERROR: fk1625798e3306904b referential integrity violation - key in message_multi_strings still referenced from sign_messages

[junit] (JDBCException.java:38) ERROR - could not delete: [com.transdyn.dynac.device.signs.messages.MessageMultiString#dc7df703-b2bd-4677-839b-0d7c24c58efd]
[junit] java.sql.SQLException: ERROR: fk1625798e3306904b referential integrity violation - key in message_multi_strings
still referenced from sign_messages

[junit] at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
[junit] at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:505)
[junit] at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:320)
[junit] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
[junit] at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:197)
[junit] at net.sf.hibernate.persister.NormalizedEntityPersister.delete(NormalizedEntityPersister.java:609)
[junit] at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
[junit] at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
[junit] at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2340)
[junit] at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
[junit] at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:202)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:151)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.deleteAll(HibernateTemplate.java:312)
[junit] at com.transdyn.dynac.device.signs.service.eis.impl.HibernateVmsSignMessageDAO.deleteVmsSignMessages(Unknown
Source)
[junit] at com.transdyn.dynac.device.signs.service.impl.DefaultVmsSignMessageManagerTest.testDeleteVmsSignMessages(Unknown Source)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:324)
[junit] at junit.framework.TestCase.runTest(TestCase.java:154)
[junit] at junit.framework.TestCase.runBare(TestCase.java:127)
[junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
[junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
[junit] at junit.framework.TestResult.run(TestResult.java:109)
[junit] at junit.framework.TestCase.run(TestCase.java:118)
[junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[junit] at junit.framework.TestSuite.run(TestSuite.java:203)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:523)
[junit] (SessionImpl.java:2343) ERROR - Could not synchronize database state with session
[junit] net.sf.hibernate.JDBCException: could not delete: [com.transdyn.dynac.device.signs.messages.MessageMultiString#dc7df703-b2bd-4677-839b-0d7c24c58efd]
[junit] at net.sf.hibernate.persister.NormalizedEntityPersister.delete(NormalizedEntityPersister.java:625)
[junit] at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
[junit] at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
[junit] at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2340)
[junit] at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
[junit] at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:202)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:151)
[junit] at org.springframework.orm.hibernate.HibernateTemplate.deleteAll(HibernateTemplate.java:312)
[junit] at com.transdyn.dynac.device.signs.service.eis.impl.HibernateVmsSignMessageDAO.deleteVmsSignMessages(Unknown
Source)
[junit] at com.transdyn.dynac.device.signs.service.impl.DefaultVmsSignMessageManagerTest.testDeleteVmsSignMessages(Unknown Source)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:324)
[junit] at junit.framework.TestCase.runTest(TestCase.java:154)
[junit] at junit.framework.TestCase.runBare(TestCase.java:127)
[junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
[junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
[junit] at junit.framework.TestResult.run(TestResult.java:109)
[junit] at junit.framework.TestCase.run(TestCase.java:118)
[junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[junit] at junit.framework.TestSuite.run(TestSuite.java:203)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:523)
[junit] Caused by: java.sql.SQLException: ERROR: fk1625798e3306904b referential integrity violation - key in message_multi_strings still referenced from sign_messages

[junit] at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
[junit] at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:505)
[junit] at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:320)
[junit] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
[junit] at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:197)
[junit] at net.sf.hibernate.persister.NormalizedEntityPersister.delete(NormalizedEntityPersister.java:609)
[junit] ... 23 more
[junit] Tests run: 5, Failures: 1, Errors: 2, Time elapsed: 3.051 sec


[b]Name and version of the database you are using: PostgreSQL 7.3.4[/b]

[b]Debug level Hibernate log excerpt:[/b]


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

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.