Hi,
I have a problem with cascading delete.
I have a set of tables that are linked with bidirectional many-to-one/one-to-many, like this:
<class name=A table=A> ... <set name="B" lazy="false" inverse="true" cascade="all"> <key column="b"/> <one-to-many not-found="ignore" class="B"/> </set> </class>
<class name="B" table="B"> ... <many-to-one name="A" column="a" class="A" lazy="false" cascade="all" /> </class>
I would like any entry of B referenced by a certain entry in A to be deleted when the entry of A is deleted, but not the other way around (deleting an entry of B shouldn't delete any entries of A). At the moment this works the exact opposite, it cascades from B to A, but when i delete an element in A that is connected to an entry in B, i get the following error message:
javax.servlet.ServletException: org.hibernate.exception.ConstraintViolationException: could not delete: [xxx.persistence.persistentclasses.A#32768] org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422) com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129) com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77) org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99) org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause
org.hibernate.exception.ConstraintViolationException: could not delete: [xxx.persistence.persistentclasses.A#32768] org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2710) org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2893) org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97) org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
I have tried with different values for cascade and inverse, with no appearant difference. What am i doing wrong here?
- Tobb
|