Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] Integrity constraint violation on delete
[Teneo] Integrity constraint violation on delete [message #421969] Tue, 19 August 2008 18:36 Go to next message
Eclipse UserFriend
Originally posted by: tskaufma.gmail.com

Hello,

I have an RCP application that uses 2 ecore models. The second model
references the first.

Simply put, the first contains a Person with attributes and references
within the model. The second model contains an Event class which has a
non-containment reference to Person objects called attendees.

What I want to do is delete a Person. When I either remove a contact from
the Resource.getContents() list or use ECoreUtils.delete(person) and then
save the resource I get an exception,


org.eclipse.emf.teneo.hibernate.HbMapperException: Exception when saving
resource DepConDataStore
at
org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:364)
at
org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou rce.java:396)
....
Caused by: org.hibernate.exception.ConstraintViolationException: could not
delete: [Person#4]
at
org.hibernate.exception.SQLStateConverter.convert(SQLStateCo nverter.java:71)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExce ptionHelper.java:43)
at
org.hibernate.persister.entity.AbstractEntityPersister.delet e(AbstractEntityPersister.java:2541)
....
Caused by: java.sql.SQLException: Integrity constraint violation
EVENT_ATTENDEES table: event_attendees in statement [delete from "contact"
where e_id=? and e_version=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
at
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUp date(NewProxyPreparedStatement.java:105)
at
org.hibernate.persister.entity.AbstractEntityPersister.delet e(AbstractEntityPersister.java:2523)
... 77 more


What is the right way to deal with this? Is there options I need to set? or
do I somehow need to get the 2nd model to remove its reference?

Thanks,
Trevor Kaufman
Re: [Teneo] Integrity constraint violation on delete [message #421979 is a reply to message #421969] Tue, 19 August 2008 20:37 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Trevor,
I am not sure but do you mean how to deal with integrity constraint exceptions?
Hibernate does not have a nullify-on-delete option in its mapping. So the only thing is either catch
the exception or do a check upfront (using a delete listener).
For a check one thing which can help is use the DataStore.getCrossReferencers method which returns
all the referencing objects. Then you can decide what do to do with the references yourselve.

gr. Martin

Trevor Kaufman wrote:
> Hello,
>
> I have an RCP application that uses 2 ecore models. The second model
> references the first.
>
> Simply put, the first contains a Person with attributes and references
> within the model. The second model contains an Event class which has a
> non-containment reference to Person objects called attendees.
>
> What I want to do is delete a Person. When I either remove a contact
> from the Resource.getContents() list or use ECoreUtils.delete(person)
> and then save the resource I get an exception,
>
>
> org.eclipse.emf.teneo.hibernate.HbMapperException: Exception when saving
> resource DepConDataStore
> at
> org.eclipse.emf.teneo.hibernate.resource.HibernateResource.s aveResource(HibernateResource.java:364)
>
> at
> org.eclipse.emf.teneo.resource.StoreResource.save(StoreResou rce.java:396)
> ....
> Caused by: org.hibernate.exception.ConstraintViolationException: could
> not delete: [Person#4]
> at
> org.hibernate.exception.SQLStateConverter.convert(SQLStateCo nverter.java:71)
>
> at
> org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExce ptionHelper.java:43)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.delet e(AbstractEntityPersister.java:2541)
>
> ....
> Caused by: java.sql.SQLException: Integrity constraint violation
> EVENT_ATTENDEES table: event_attendees in statement [delete from
> "contact" where e_id=? and e_version=?]
> at org.hsqldb.jdbc.Util.throwError(Unknown Source)
> at org.hsqldb.jdbc.jdbcPreparedStatement.executeUpdate(Unknown Source)
> at
> com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUp date(NewProxyPreparedStatement.java:105)
>
> at
> org.hibernate.persister.entity.AbstractEntityPersister.delet e(AbstractEntityPersister.java:2523)
>
> ... 77 more
>
>
> What is the right way to deal with this? Is there options I need to set?
> or do I somehow need to get the 2nd model to remove its reference?
>
> Thanks,
> Trevor Kaufman


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Previous Topic:How to implement derived and volatile getters?
Next Topic:ExtensibleURIConver BUG ?
Goto Forum:
  


Current Time: Tue Apr 23 14:48:24 GMT 2024

Powered by FUDForum. Page generated in 0.03097 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top