Issues with Cascade and Multiple rows
by Alex Turner
Can somebody point me to a resource, or just plain clue me in on the whole
Cascade thing. If I don't cascade I get nasty errors about transient
objects, but if I do cascade, I get the same java object saved 6 times
creating 6 rows in the database when I save parts of a collection that
reference the parent. How can the same identical Java object get persisted
6 seperate times to create 6 different rows? That to me would seem like
behaviour that was unexpected at least, I didn't expect it!!
Thanks,
Alex
15 years, 12 months
Problem persisting a set of object
by Alex Turner
I have two questions:
1) I thought the entity at the source end of a OneToMany defined by
annotations didn't care about it's collection and would ignore updates to
the collection? (this is the first problem, I got around it by settings
cascade = CascadeType.ALL because if it does persist it's list that's not a
bad thing, it's just not what I was expecting)
2) After doing that, I get the following error. As far as I can tell all my
Entities have generated ids, so I don't really undefrstand how I could have
an object with a null id other than the fact that it's null because it has
yet to be populated with a generated id.
00:41:15:ERROR org.hibernate.AssertionFailure (AssertionFailure.java:22) -
an assertion failure occured (this may indicate a bug in Hibernate, but is
more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: cannot copy a reference to an object with a
null id
at org.hibernate.type.EntityType.replace(EntityType.java:255)
at org.hibernate.type.AbstractType.replace(AbstractType.java:153)
at
org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:564)
at
org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:366)
at
org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:195)
at
org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at
org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at
org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:228)
at com.tmdworldwide.projectmanager.persist.BaseDao.save(BaseDao.java:37)
at
com.tmdworldwide.projectmanager.web.product.ProductActionBean.createProject(ProductActionBean.java:49)
at
com.tmdworldwide.projectmanager.web.product.CreateTrifoldBrochureActionBean.createProject(CreateTrifoldBrochureActionBean.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
net.sourceforge.stripes.controller.DispatcherHelper$6.intercept(DispatcherHelper.java:442)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:158)
at
org.stripesstuff.plugin.security.SecurityInterceptor.interceptEventHandling(SecurityInterceptor.java:191)
at
org.stripesstuff.plugin.security.SecurityInterceptor.intercept(SecurityInterceptor.java:123)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at
net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at
net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at
net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74)
at
net.sourceforge.stripes.controller.DispatcherHelper.invokeEventHandler(DispatcherHelper.java:440)
at
net.sourceforge.stripes.controller.DispatcherServlet.invokeEventHandler(DispatcherServlet.java:285)
at
net.sourceforge.stripes.controller.DispatcherServlet.doPost(DispatcherServlet.java:167)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:246)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:637)
00:41:15: WARN net.sourceforge.stripes.exception.DefaultExceptionHandler
(Log.java:90) - Unhandled exception caught by the Stripes default exception
handler.
org.hibernate.AssertionFailure: cannot copy a reference to an object with a
null id
at org.hibernate.type.EntityType.replace(EntityType.java:255)
at org.hibernate.type.AbstractType.replace(AbstractType.java:153)
at
org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:564)
at
org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:366)
at
org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:195)
at
org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
at
org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
at
org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:228)
at com.tmdworldwide.projectmanager.persist.BaseDao.save(BaseDao.java:37)
at
com.tmdworldwide.projectmanager.web.product.ProductActionBean.createProject(ProductActionBean.java:49)
at
com.tmdworldwide.projectmanager.web.product.CreateTrifoldBrochureActionBean.createProject(CreateTrifoldBrochureActionBean.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
net.sourceforge.stripes.controller.DispatcherHelper$6.intercept(DispatcherHelper.java:442)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:158)
at
org.stripesstuff.plugin.security.SecurityInterceptor.interceptEventHandling(SecurityInterceptor.java:191)
at
org.stripesstuff.plugin.security.SecurityInterceptor.intercept(SecurityInterceptor.java:123)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at
net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at
net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
at
net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
at
net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74)
at
net.sourceforge.stripes.controller.DispatcherHelper.invokeEventHandler(DispatcherHelper.java:440)
at
net.sourceforge.stripes.controller.DispatcherServlet.invokeEventHandler(DispatcherServlet.java:285)
at
net.sourceforge.stripes.controller.DispatcherServlet.doPost(DispatcherServlet.java:167)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:246)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:637)
15 years, 12 months