5 Replies Latest reply on May 22, 2008 2:39 AM by rkiran81

    OneToMany Unidirectional EntityManager remove() problem

    rkiran81

      Hi All,

      My development environment is jboss-4.0.3SP1 server and used jboss-EJB-3.0_RC6-PFD to setup my jboss for ejb3.
      MSSQL Server 2005.

      I have 2 tables.

      Parent table with columns PROFILE_ID(bigint) and PROFILE_NAME(nvarchar(64))

      Parent Table Bean
      @Entity
      @Table(name="PROFILES")
      public class DomainProfileBean implements Serializable
      {
      static final long serialVersionUID = 5421650648474888865L;
      private long id;
      private String profileName;
      private Collection queryProfileBean = new ArrayList();

      @Id
      @Column(name="PROFILE_ID")
      public long getId()
      {
      return id;
      }

      public void setId(long id)
      {
      this.id = id;
      }
      @Column(name="PROFILE_NAME")
      public String getProfileName()
      {
      return profileName;
      }
      public void setProfileName(String profileName)
      {
      this.profileName = profileName;
      }

      @OneToMany(cascade = {CascadeType.ALL})
      @JoinColumn(name="PROFILE_ID")
      public Collection getQueryProfileBean()
      {
      return queryProfileBean;
      }

      public void setQueryProfileBean(Collection queryProfileBean)
      {
      this.queryProfileBean = queryProfileBean;
      }
      }
      -----------------------------------------------------------------------------------

      Child table with columns ID(bigint),PROFILE_ID(bigint) and QUERY_ID(bigint)

      Child Table Bean
      @Entity
      @Table(name="LK_PROFILE_QUERY")
      public class QueryProfileBean implements Serializable
      {
      static final long serialVersionUID = 258127495705939407L;
      private long id;
      private long profileID;
      private long queryID;

      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="ID")
      public long getId()
      {
      return id;
      }

      public void setId(long id)
      {
      this.id = id;
      }

      @Column(name="PROFILE_ID")
      public long getProfileID()
      {
      return profileID;
      }

      public void setProfileID(long profileID)
      {
      this.profileID = profileID;
      }

      @Column(name="QUERY_ID")
      public long getQueryID()
      {
      return queryID;
      }

      public void setQueryID(long queryID)
      {
      this.queryID = queryID;
      }
      }
      ----------------------------------------------------------------------------

      i already have 5 entries in child table.

      Now from sessionbean(stateless)
      DomainProfileBean domainProfileBean = entityManager.find(DomainProfileBean.class, domainProfileID);
      Collection queryProfileBeanList = domainProfileBean.getQueryProfileBean();

      and now remove any 2 QueryProfileBean objects from the collection and call entityManager.flush() i get the error

      11:38:32,517 INFO [STDOUT] Hibernate: update LK_PROFILE_QUERY set PROFILE_ID=null where PROFILE_ID=? and ID=?
      11:38:32,533 WARN [JDBCExceptionReporter] SQL Error: 515, SQLState: 23000
      11:38:32,533 ERROR [JDBCExceptionReporter] Cannot insert the value NULL into column 'PROFILE_ID', table 'QAUsers.dbo.LK_
      PROFILE_QUERY'; column does not allow nulls. UPDATE fails.
      11:38:32,533 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.ConstraintViolationException: could not delete collection rows: [com.bis.dbservices.domainprofil
      edao.DomainProfileBean.queryProfileBean#7106367]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      at org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:11
      40)
      at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:54)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:29
      7)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
      at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:271)
      at org.jboss.ejb3.entity.TransactionScopedEntityManager.flush(TransactionScopedEntityManager.java:204)
      at com.bis.dbservices.domainprofiledao.DomainProfileEJB3SLBean.updateDomainProfile(DomainProfileEJB3SLBean.java:
      353)
      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:109)
      at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerIntercep
      tor.java:54)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:225)
      at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:55)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
      at $Proxy162.updateDomainProfile(Unknown Source)
      at com.bis.dbservices.domainprofiledao.DomainProfileHandler.updateDomainProfile(DomainProfileHandler.java:164)
      at com.bis.sysadmintool.domain.servlets.DAAddRemoveQueriesServlet.service(DAAddRemoveQueriesServlet.java:401)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.bis.commonclasses.RequestEncodingFilter.doFilter(RequestEncodingFilter.java:87)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: java.sql.SQLException: Cannot insert the value NULL into column 'PROFILE_ID', table 'QAUsers.dbo.LK_PROFILE_Q
      UERY'; column does not allow nulls. UPDATE fails.
      at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
      at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
      at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
      at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
      at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:525)
      at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:487)
      at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:421)
      at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:227)
      at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
      at org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:11
      23)
      ... 62 more
      11:38:32,548 ERROR [[DAAddRemoveQueriesServlet]] Servlet.service() for servlet DAAddRemoveQueriesServlet threw exception

      javax.ejb.EJBException: javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: c
      ould not delete collection rows: [com.bis.dbservices.domainprofiledao.DomainProfileBean.queryProfileBean#7106367]
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:225)
      at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:55)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
      at $Proxy162.updateDomainProfile(Unknown Source)
      at com.bis.dbservices.domainprofiledao.DomainProfileHandler.updateDomainProfile(DomainProfileHandler.java:164)
      at com.bis.sysadmintool.domain.servlets.DAAddRemoveQueriesServlet.service(DAAddRemoveQueriesServlet.java:401)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at com.bis.commonclasses.RequestEncodingFilter.doFilter(RequestEncodingFilter.java:87)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationException: could not dele
      te collection rows: [com.bis.dbservices.domainprofiledao.DomainProfileBean.queryProfileBean#7106367]
      at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:550)
      at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:274)
      at org.jboss.ejb3.entity.TransactionScopedEntityManager.flush(TransactionScopedEntityManager.java:204)
      at com.bis.dbservices.domainprofiledao.DomainProfileEJB3SLBean.updateDomainProfile(DomainProfileEJB3SLBean.java:
      353)
      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:109)
      at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerIntercep
      tor.java:54)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
      ... 42 more
      Caused by: org.hibernate.exception.ConstraintViolationException: could not delete collection rows: [com.bis.dbservices.d
      omainprofiledao.DomainProfileBean.queryProfileBean#7106367]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
      at org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:11
      40)
      at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:54)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:29
      7)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
      at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:271)
      ... 54 more
      Caused by: java.sql.SQLException: Cannot insert the value NULL into column 'PROFILE_ID', table 'QAUsers.dbo.LK_PROFILE_Q
      UERY'; column does not allow nulls. UPDATE fails.
      at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
      at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
      at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
      at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
      at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:525)
      at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:487)
      at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:421)
      at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:227)
      at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
      at org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:11
      23)
      ... 62 more

      Can anybody please help on this.

        • 1. Re: OneToMany Unidirectional EntityManager remove() problem
          rkiran81

          The PROFILE_ID column in Child table "LK_PROFILE_QUERY" does not allow null.
          i modified it to allow null values, deletion works properly.

          But i dont want that to allow null values. So how could i proceed further.

          • 2. Re: OneToMany Unidirectional EntityManager remove() problem
            jaikiran

            Add an additional annotation org.hibernate.annotations.Cascade to your OneToMany mapping, as follows:

            @OneToMany(cascade = {CascadeType.ALL})
            @JoinColumn(name="PROFILE_ID")
            @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
            public Collection getQueryProfileBean()
            {
            return queryProfileBean;
            }


            • 3. Re: OneToMany Unidirectional EntityManager remove() problem
              rkiran81

              Hi JaiKiran,

              Still am getting the same error.
              CascadeType.ALL takes care of deleting refrenced child entries also know, then how does org.hibernate.annotations.CascadeType.DELETE_ORPHAN help. But anyway it dint work sir. Could you please suggest any other options.

              • 4. Re: OneToMany Unidirectional EntityManager remove() problem
                jaikiran

                 

                "rkiran81" wrote:
                Hi JaiKiran,

                Still am getting the same error.

                Please post the latest exception stacktrace and the code changes that you have done. While posting the logs or xml content or code, remember to wrap it in a code block using the Code button in the message editor window and please hit the Preview button to make sure your post is correctly formatted. Also, are you sure that your changes were picked up?

                "rkiran81" wrote:

                CascadeType.ALL takes care of deleting refrenced child entries also know, then how does org.hibernate.annotations.CascadeType.DELETE_ORPHAN help.


                Well, that's what i thought earlier. I expected the child to be deleted from the DB when you remove it from a collection and save the parent. But thinking more about it and reading through this thread http://forum.hibernate.org/viewtopic.php?p=2376122, i understand that the org.hibernate.annotations.CascadeType.DELETE_ORPHAN is required in this case. In the scenario, we are discussing, we remove the child from a collection of the parent and persist the parent. While persisting the parent Hibernate sees that the "association" between the parent and the child has been removed and hence tries to set the parent id in the child table to NULL. If that column allows NULL then you won't see any exception but if it doesn't (which means that the child cannot exist without a parent) then it throws the constraint violation. So if you want Hibernate to remove the child when the "association" with its parent is removed then you have to add the org.hibernate.annotations.CascadeType.DELETE_ORPHAN annotation (Thinking more about this common scenario, i don't know why JPA does not provide an annotation for this instead of relying on vendor specific annotation).



                • 5. Re: OneToMany Unidirectional EntityManager remove() problem
                  rkiran81

                  Hi JaiKiran,

                  Thanks for your reply.

                  With Child PROFILE_ID (parent id) column Allowing Not Null values, below is the code and stack trace.
                  
                  @OneToMany(cascade = {CascadeType.ALL})
                  @JoinColumn(name="PROFILE_ID")
                  @org.hibernate.annotations.Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
                  public Collection getQueryProfileBean()
                  {
                  return queryProfileBean;
                  }
                  11:44:13,310 WARN [JDBCExceptionReporter] SQL Error: 515, SQLState: 23000
                  11:44:13,310 ERROR [JDBCExceptionReporter] Cannot insert the value NULL into column 'PROFILE_ID', table 'QAUsers.dbo.LK_
                  PROFILE_QUERY'; column does not allow nulls. UPDATE fails.
                  11:44:13,325 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
                  org.hibernate.exception.ConstraintViolationException: could not delete collection rows: [com.bis.dbservices.domainprofil
                  edao.DomainProfileBean.queryProfileBean#7106370]
                   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
                   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
                   at org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:11
                  40)
                   at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:54)
                   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
                   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
                   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
                   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:29
                  7)
                  With Child PROFILE_ID (parent id) column Allowing Null values, below is the code.
                  
                  @OneToMany(cascade = {CascadeType.ALL})
                  @JoinColumn(name="PROFILE_ID")
                  public Collection getQueryProfileBean()
                  {
                  return queryProfileBean;
                  }
                  
                  Works fine.


                  org.hibernate.annotations.CascadeType.DELETE_ORPHAN is not helping in any way. Just make the parent id in child table to allow null and CascadeType.ALL will do the job.

                  It actually inserts null and then deletes the column. This is what i found.

                  Even am trying to find any other way for this ie.. with parent id column to allow nulls, if you get any idea on this please update the same.

                  Thank you very much for your support.