1 Reply Latest reply on Jun 22, 2006 12:18 AM by Vijay Phagura

    Cannot insert into composite Object in the database with @On

    Vijay Phagura Newbie

      I have two classes Measurement and Counts they have a One to Many relation. I have the following annotations in place:

      Measurement:
      ...
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy="measurement")

      public List< Counts > getCounts()
      {
      return counts;
      }

      Counts;
      ...
      @ManyToOne
      @JoinColumn(name = "measurement_id")
      public Measurement getMeasurement()
      {
      return measurement;
      }

      I've used both JBOSS version 4.0.4 GA and 4.0.3 SP1 and it is the same problem. It gives following exception:

      javax.ejb.EJBExcepti
      on: javax.persistence.PersistenceException: org.hibernate.NonUniqueObjectExcepti
      on: a different object with the same identifier value was already associated wit
      h the session: [com.theranos.abcs.reader.dmo.Counts#0]
      15:52:23,073 ERROR [STDERR] javax.ejb.EJBException: javax.persistence.Persistenc
      eException: org.hibernate.NonUniqueObjectException: a different object with the
      same identifier value was already associated with the session: [com.theranos.abc
      s.reader.dmo.Counts#0]
      15:52:23,073 ERROR [STDERR] at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptio
      nInOurTx(Ejb3TxPolicy.java:69)
      15:52:23,073 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(T
      xPolicy.java:83)
      15:52:23,073 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.i
      nvoke(TxInterceptor.java:197)
      15:52:23,073 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,073 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor
      .invoke(TxPropagationInterceptor.java:76)
      15:52:23,088 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,088 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulInstanceInter
      ceptor.invoke(StatefulInstanceInterceptor.java:81)
      15:52:23,088 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,088 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInte
      rceptor.invoke(AuthenticationInterceptor.java:78)
      15:52:23,088 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,088 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invo
      ke(ENCPropagationInterceptor.java:47)
      15:52:23,088 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,088 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInter
      ceptor.invoke(AsynchronousInterceptor.java:106)
      15:52:23,088 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,088 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulContainer.loc
      alInvoke(StatefulContainer.java:199)
      15:52:23,088 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulLocalProxy.in
      voke(StatefulLocalProxy.java:98)
      15:52:23,088 ERROR [STDERR] at $Proxy79.addMeasurement(Unknown Source)
      15:52:23,088 ERROR [STDERR] at com.theranos.abcs.utils.LogParser.parse(LogPa
      rser.java:247)
      15:52:23,088 ERROR [STDERR] at com.theranos.abcs.reader.web.servlet.ReaderSe
      rver.parseLogs(ReaderServer.java:247)
      15:52:23,104 ERROR [STDERR] at com.theranos.abcs.reader.web.servlet.ReaderSe
      rver.doPost(ReaderServer.java:147)
      15:52:23,104 ERROR [STDERR] at com.theranos.abcs.reader.web.servlet.ReaderSe
      rver.doGet(ReaderServer.java:105)
      15:52:23,104 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
      rvlet.java:697)
      15:52:23,104 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
      rvlet.java:810)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
      in.internalDoFilter(ApplicationFilterChain.java:252)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
      in.doFilter(ApplicationFilterChain.java:173)
      15:52:23,104 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilte
      r.doFilter(ReplyHeaderFilter.java:96)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
      in.internalDoFilter(ApplicationFilterChain.java:202)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
      in.doFilter(ApplicationFilterChain.java:173)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve
      .invoke(StandardWrapperValve.java:213)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve
      .invoke(StandardContextValve.java:178)
      15:52:23,104 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssocia
      tionValve.invoke(SecurityAssociationValve.java:175)
      15:52:23,104 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValv
      e.invoke(JaccContextValve.java:74)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.in
      voke(StandardHostValve.java:126)
      15:52:23,104 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.i
      nvoke(ErrorReportValve.java:105)
      15:52:23,120 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.
      invoke(StandardEngineValve.java:107)
      15:52:23,120 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.s
      ervice(CoyoteAdapter.java:148)
      15:52:23,120 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.proc
      ess(Http11Processor.java:869)
      15:52:23,120 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$H
      ttp11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      15:52:23,120 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.pr
      ocessSocket(PoolTcpEndpoint.java:527)
      15:52:23,120 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerT
      hread.run(MasterSlaveWorkerThread.java:112)
      15:52:23,120 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
      15:52:23,120 ERROR [STDERR] Caused by: javax.persistence.PersistenceException: o
      rg.hibernate.NonUniqueObjectException: a different object with the same identifi
      er value was already associated with the session: [com.theranos.abcs.reader.dmo.
      Counts#0]
      15:52:23,120 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.t
      hrowPersistenceException(AbstractEntityManagerImpl.java:567)
      15:52:23,135 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.p
      ersist(AbstractEntityManagerImpl.java:192)
      15:52:23,135 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntity
      Manager.persist(TransactionScopedEntityManager.java:175)
      15:52:23,135 ERROR [STDERR] at com.theranos.abcs.reader.ejb.MeasurementAcces
      sorBean.addMeasurement(MeasurementAccessorBean.java:72)
      15:52:23,135 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      15:52:23,135 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)
      15:52:23,135 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
      ke(DelegatingMethodAccessorImpl.java:25)
      15:52:23,135 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:5
      85)
      15:52:23,135 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:112)
      15:52:23,135 ERROR [STDERR] at org.jboss.ejb3.interceptor.InvocationContextI
      mpl.proceed(InvocationContextImpl.java:166)
      15:52:23,135 ERROR [STDERR] at org.jboss.ejb3.interceptor.EJB3InterceptorsIn
      terceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      15:52:23,135 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,135 ERROR [STDERR] at org.jboss.ejb3.entity.ExtendedPersistenceCont
      extPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationIntercepto
      r.java:57)
      15:52:23,151 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,151 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntity
      ManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      15:52:23,151 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,151 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.i
      nvoke(AllowedOperationsInterceptor.java:47)
      15:52:23,151 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invo
      keNext(MethodInvocation.java:101)
      15:52:23,151 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(T
      xPolicy.java:79)
      15:52:23,151 ERROR [STDERR] ... 39 more
      15:52:23,151 ERROR [STDERR] Caused by: org.hibernate.NonUniqueObjectException: a
      different object with the same identifier value was already associated with the
      session: [com.theranos.abcs.reader.dmo.Counts#0]
      15:52:23,151 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
      ener.performSave(AbstractSaveEventListener.java:167)
      15:52:23,151 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
      ener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
      15:52:23,151 ERROR [STDERR] at org.hibernate.event.def.DefaultPersistEventLi
      stener.entityIsTransient(DefaultPersistEventListener.java:131)
      15:52:23,151 ERROR [STDERR] at org.hibernate.event.def.DefaultPersistEventLi
      stener.onPersist(DefaultPersistEventListener.java:87)
      15:52:23,166 ERROR [STDERR] at org.hibernate.impl.SessionImpl.firePersist(Se
      ssionImpl.java:611)
      15:52:23,166 ERROR [STDERR] at org.hibernate.impl.SessionImpl.persist(Sessio
      nImpl.java:603)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.CascadingAction$8.cascad
      e(CascadingAction.java:202)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeToOne(Cas
      cade.java:213)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeAssociati
      on(Cascade.java:157)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeProperty(
      Cascade.java:108)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeCollectio
      nElements(Cascade.java:290)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeCollectio
      n(Cascade.java:185)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeAssociati
      on(Cascade.java:160)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeProperty(
      Cascade.java:108)
      15:52:23,166 ERROR [STDERR] at org.hibernate.engine.Cascade.cascade(Cascade.
      java:248)
      15:52:23,182 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
      ener.cascadeAfterSave(AbstractSaveEventListener.java:437)
      15:52:23,182 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
      ener.performSaveOrReplicate(AbstractSaveEventListener.java:326)
      15:52:23,182 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
      ener.performSave(AbstractSaveEventListener.java:180)
      15:52:23,182 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
      ener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
      15:52:23,182 ERROR [STDERR] at org.hibernate.event.def.DefaultPersistEventLi
      stener.entityIsTransient(DefaultPersistEventListener.java:131)
      15:52:23,182 ERROR [STDERR] at org.hibernate.event.def.DefaultPersistEventLi
      stener.onPersist(DefaultPersistEventListener.java:87)
      15:52:23,182 ERROR [STDERR] at org.hibernate.event.def.DefaultPersistEventLi
      stener.onPersist(DefaultPersistEventListener.java:38)
      15:52:23,182 ERROR [STDERR] at org.hibernate.impl.SessionImpl.firePersist(Se
      ssionImpl.java:620)
      15:52:23,182 ERROR [STDERR] at org.hibernate.impl.SessionImpl.persist(Sessio
      nImpl.java:594)
      15:52:23,182 ERROR [STDERR] at org.hibernate.impl.SessionImpl.persist(Sessio
      nImpl.java:598)
      15:52:23,182 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.p
      ersist(AbstractEntityManagerImpl.java:186)
      15:52:23,182 ERROR [STDERR] ... 56 more


      The database I'm using is MySQL so my Dialect is set to that. PLease help!! Any help would appreciated.

      Vijay