Hibernate version:
2.1.6
Name and version of the database you are using:
Mysql 4.0.20d
Here is my setup:
I have a User object that has a Set of CustomLayout objects mapped as a one-to-many.
I am having trouble deleting one of the custom layouts from the Set.
Here are my mapping files:
User.hbm.xml
------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.schmoozenews.user.domain.User" table="USER">
<id name="username" column="username" type="string" length="31">
<generator class="assigned"/>
</id>
<property name="password" column="password" type="string" length="15" unique="false" not-null="true"/>
<property name="email" column="email" type="string" length="127" unique="false" not-null="true"/>
<property name="location" column="location" type="string" length="127" unique="false" not-null="true"/>
<property name="signature" column="sig" type="string" length="255" unique="false" not-null="false"/>
<property name="bio" column="bio" type="string" length="4096" unique="false" not-null="false"/>
<property name="homepage" column="homepage" type="string" length="255" unique="false" not-null="false"/>
<property name="imageURL" column="image_url" type="string" length="255" unique="false" not-null="false"/>
<property name="yim" column="yim" type="string" length="32" unique="false" not-null="false"/>
<property name="aim" column="aim" type="string" length="32" unique="false" not-null="false"/>
<property name="msm" column="msm" type="string" length="32" unique="false" not-null="false"/>
<property name="dateOfBirth" column="date_of_birth" type="date" unique="false" not-null="true"/>
<property name="sessionId" column="session_id" type="long" unique="false" not-null="false"/>
<property name="spamOk" column="spam_ok" type="yes_no"/>
<property name="emailAlert" column="email_alert" type="yes_no" not-null="true"/>
<set name="customLayouts" table="user_custom_layouts" cascade="all-delete-orphan" inverse="true" order-by="name">
<key column="username"/>
<one-to-many class="com.schmoozenews.user.layout.domain.CustomLayout"/>
</set>
</class>
</hibernate-mapping>
CustomLayout.hbm.xml
--------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.schmoozenews.user.layout.domain.CustomLayout" table="custom_layout">
<id name="customLayoutId" column="custom_layout_id" type="long">
<generator class="native"/>
</id>
<property name="name" column="name" type="string" length="32" unique="false" not-null="true"/>
<property name="defaultLayout" column="default_layout" type="yes_no" not-null="true"/>
<many-to-one name="user" class="com.schmoozenews.user.domain.User" column="username" />
<list name="categoryListNodes" table="custom_layout_category_list" inverse="true" cascade="all" >
<key column="custom_layout_id"/>
<index column="sequence_number"/>
<composite-element class="com.schmoozenews.user.layout.domain.CategoryListNode">
<many-to-one name="category" class="com.schmoozenews.category.domain.Category" column="category_id"/>
</composite-element>
</list>
</class>
</hibernate-mapping>
I am using the spring framework with the TransactionTemplate, so here is the code to delete a customLayout from a user:
/**
* @see com.schmoozenews.user.dao.UserDAO#add(com.schmoozenews.user.layout.domain.CustomLayout)
*/
public void delete(final User user, final CustomLayout customLayout) throws HibernateException
{
TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(TransactionStatus status) {
try {
user.getCustomLayouts().remove(customLayout);
userDAO.delete(customLayout);
} catch (HibernateException he) {
SessionFactoryUtils.convertHibernateAccessException(he);
}
}
});
}
Here is the userDao.delete(CustomLayout) method:
/**
* @see com.schmoozenews.user.dao.UserDAO#delete(com.schmoozenews.user.layout.domain.CustomLayout)
*/
public void delete(CustomLayout customLayout) throws HibernateException
{
getHibernateTemplate().delete(customLayout);
}
When I call delete(user,customLayout) , I get the following exception:
net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 14, of class: com.schmoozenews.user.layout.domain.CustomLayout
at net.sf.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:734)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:712)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1347)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2639)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2214)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2203)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:386)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:316)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:126)
at com.schmoozenews.user.service.UserServiceImpl.delete(UserServiceImpl.java:86)
at com.schmoozenews.struts.user.action.CustomLayoutListPostAction.executeUpdateAction(CustomLayoutListPostAction.java:69)
at com.schmoozenews.struts.user.action.UpdateAction.executeAction(UpdateAction.java:56)
at com.schmoozenews.struts.global.action.BaseCategoryAction.execute(BaseCategoryAction.java:98)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:131)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:117)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
|