[jboss-user] [EJB 3.0] - Unidirectional ManyToMany empty collection

fospitia do-not-reply at jboss.com
Wed Apr 30 05:39:19 EDT 2008


Hi

I have a problem with a Entity with 3 unidirectional ManyToMany collections. The entity is:


  | public class Media implements Serializable, Comparable<Media> {
  | .. 
  | 
  | 	@javax.persistence.ManyToMany( cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.MERGE } )
  | 	@javax.persistence.JoinTable(name = "nv_media_category", joinColumns = @javax.persistence.JoinColumn(name = "media_id", nullable = false), inverseJoinColumns = @javax.persistence.JoinColumn(name = "category_id", nullable = false))
  | 	private Set<Category> categories = new HashSet<Category>();
  | 	@javax.persistence.ManyToMany( cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.MERGE } )
  | 	@javax.persistence.JoinTable(name = "nv_media_content", joinColumns = @javax.persistence.JoinColumn(name = "media_id", nullable = false), inverseJoinColumns = @javax.persistence.JoinColumn(name = "content_id", nullable = false))
  | 	private Set<Content> contents = new HashSet<Content>();
  | 	@javax.persistence.ManyToMany( cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.MERGE } )
  | 	@javax.persistence.JoinTable(name = "nv_media_comment", joinColumns = @javax.persistence.JoinColumn(name = "media_id", nullable = false), inverseJoinColumns = @javax.persistence.JoinColumn(name = "comment_id", nullable = false))
  | 	private Set<Comment> comments = new HashSet<Comment>();
  | 
  | ..
  | 
  | }
  | 

The problem is when create a new Media Entity and the collection comments is empty the follow code give a exception in the emanager.flush();


  | 
  | 		try {
  | 			emanager.persist(media);
  | 			emanager.flush();
  | 		} catch (Exception ex) {
  | 			throw new MediaDaoException(ex);
  | 		}
  | 
  | 

the exception:


  | 11:15:21,690 ERROR [MediaServiceBase] [create]Exception: com.dnovae.nova.core.media.MediaDaoException: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.dnovae.nova.core.comment.Comment.comment
  | 11:15:21,690 INFO  [PhaseInterceptorChain] Interceptor has thrown exception, unwinding now
  | java.lang.RuntimeException: com.dnovae.nova.common.media.MediaServiceException: com.dnovae.nova.core.media.MediaDaoException: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.dnovae.nova.core.comment.Comment.comment
  | 	at org.jboss.wsf.stack.cxf.AbstractInvoker.handleException(AbstractInvoker.java:149)
  | 	at org.jboss.wsf.stack.cxf.AbstractInvoker.invoke(AbstractInvoker.java:118)
  | 	at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
  | 	at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
  | 	at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92)
  | 	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:208)
  | 	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:77)
  | 	at org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDestination.java:79)
  | 	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:264)
  | 	at org.jboss.wsf.stack.cxf.ServletControllerExt.invoke(ServletControllerExt.java:133)
  | 	at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:63)
  | 	at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:136)
  | 	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 org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 	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:230)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  | 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
  | 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  | 	at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
  | 	at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:856)
  | 	at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:566)
  | 	at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
  | 	at java.lang.Thread.run(Thread.java:595)
  | Caused by: com.dnovae.nova.common.media.MediaServiceException: com.dnovae.nova.core.media.MediaDaoException: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.dnovae.nova.core.comment.Comment.comment
  | 	at com.dnovae.nova.core.media.MediaServiceBase.create(MediaServiceBase.java:77)
  | 	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:585)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
  | 	at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
  | 	at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
  | 	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)
  | 	at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:115)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
  | 	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.wsf.container.jboss42.InvocationHandlerEJB3.invoke(InvocationHandlerEJB3.java:103)
  | 	at org.jboss.wsf.stack.cxf.AbstractInvoker.invoke(AbstractInvoker.java:113)
  | 	... 29 more
  | Caused by: com.dnovae.nova.core.media.MediaDaoException: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.dnovae.nova.core.comment.Comment.comment
  | 	at com.dnovae.nova.core.media.MediaDaoBase.create(MediaDaoBase.java:257)
  | 	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:585)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
  | 	at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
  | 	at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
  | 	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)
  | 	at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:115)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
  | 	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:240)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
  | 	at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
  | 	at $Proxy183.create(Unknown Source)
  | 	at com.dnovae.nova.core.media.MediaServiceBean.handleCreate(MediaServiceBean.java:41)
  | 	at com.dnovae.nova.core.media.MediaServiceBase.create(MediaServiceBase.java:74)
  | 	... 60 more
  | Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.dnovae.nova.core.comment.Comment.comment
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
  | 	at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:182)
  | 	at com.dnovae.nova.core.media.MediaDaoBase.create(MediaDaoBase.java:253)
  | 	... 95 more
  | Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.dnovae.nova.core.comment.Comment.comment
  | 	at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
  | 	at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
  | 	at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
  | 	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
  | 	at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
  | 	at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
  | 	at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:609)
  | 	at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:601)
  | 	at org.hibernate.engine.CascadingAction$8.cascade(CascadingAction.java:295)
  | 	at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
  | 	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
  | 	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
  | 	at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
  | 	at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
  | 	at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
  | 	at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
  | 	at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
  | 	at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
  | 	at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:334)
  | 	at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
  | 	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
  | 	at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
  | 	at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
  | 	at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
  | 	at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
  | 	at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
  | 	at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:212)
  | 	... 97 more
  | 

Please, can somebody help me.

Thanks.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4147769#4147769

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4147769



More information about the jboss-user mailing list