3 Replies Latest reply on Jul 15, 2008 10:08 AM by Oskar Carlstedt

    @GeneratedValue(strategy=GenerationType.AUTO) for oracle fai

    kiran kumar Newbie

      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.
      Oracle10g.

      I have two already existing tables for which i have created the beans.

      
      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 rolesProfileBean= 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 getRolesProfileBean()
      {
      return rolesProfileBean;
      }
      
      public void setRolesProfileBean(Collection rolesProfileBean)
      {
      this.rolesProfileBean= rolesProfileBean;
      }
      }
      -----------------------------------------------------------------------------------
      
      Child table with columns ID(bigint),PROFILE_ID(bigint) and ROLE_ID(bigint)
      
      Child Table Bean
      @Entity
      @Table(name="LK_PROFILE_QUERY")
      public class RolesProfileBean implements Serializable
      {
      static final long serialVersionUID = 258127495705939407L;
      private long id;
      private long profileID;
      private long roleID;
      
      @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="ROLE_ID")
      public long getRoleID()
      {
      return roleID;
      }
      
      public void setRoleID(long roleID)
      {
      this.roleID= roleID;
      }
      }


      when am trying to persist (creating new record) my parent table bean am also populating the child table beans, but it is failing. Please check the stack trace
      12:44:30,027 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8081
      12:44:30,105 INFO [Server] JBoss (MX MicroKernel) [4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)] Started
      in 1m:41s:459ms
      12:47:58,657 INFO [FieldsManager] FieldsManager in use = org.jboss.serial.classmetamodel.UnsafeFieldsManager
      12:47:59,978 WARN [JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
      12:47:59,978 ERROR [JDBCExceptionReporter] ORA-00001: unique constraint (MPUSERS.SYS_C0031176) violated
      
      12:47:59,978 WARN [JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
      12:47:59,978 ERROR [JDBCExceptionReporter] ORA-00001: unique constraint (MPUSERS.SYS_C0031176) violated
      
      12:47:59,978 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.ConstraintViolationException: could not insert: [com.bis.dbservices.domainprofiledao.RolesProfil
      eBean]
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2140)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2503)
       at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
       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:139)
       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.impl.SessionImpl.managedFlush(SessionImpl.java:337)
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:473)
       at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1473)
       at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1092)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:306)
       at org.jboss.tm.TxManager.commit(TxManager.java:224)
       at org.jboss.ejb.EnterpriseContext$UserTransactionImpl.commit(EnterpriseContext.java:605)
       at com.bis.dbservices.domainprofiledao.DomainProfileSLBean.createDomainProfile(DomainProfileSLBean.java:209)
       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.invocation.Invocation.performCall(Invocation.java:345)
       at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
      
       at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
       at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:158)
       at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:62)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154
      )
       at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
       at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
       at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
       at org.jboss.ejb.Container.invoke(Container.java:873)
       at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
       at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:155)
       at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:104)
       at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:179)
       at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:165)
       at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
       at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:55)
       at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:97)
       at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:86)
       at $Proxy89.createDomainProfile(Unknown Source)
       at com.bis.dbservices.domainprofiledao.DomainProfileHandler.createDomainProfile(DomainProfileHandler.java:106)
       at com.bis.sysadmintool.domain.servlets.DADomainProfileCreateServlet.service(DADomainProfileCreateServlet.java:1
      99)
       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.userauthentication.windows.AuthenticationFilter.doFilter(AuthenticationFilter.java:227)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       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.BatchUpdateException: ORA-00001: unique constraint (MPUSERS.SYS_C0031176) violated
      
       at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
       at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10657)
       at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:487)
       at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
       at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:34)
       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2120)
       ... 79 more


      Can anybody please suggest on this ASAP.

        • 1. Re: @GeneratedValue(strategy=GenerationType.AUTO) for oracle
          S P Newbie

          with out being 100% sure ... did you did updates on the tables ?
          you had a working directory and changed the structure of your db ?

          Perhaps if you change you persistence xml if it is from "update" to "create-drop" to drop and recreate the database. perhaps that may synchronize the db.

          Bare in mind you will loss everything with this.


          • 2. Re: @GeneratedValue(strategy=GenerationType.AUTO) for oracle
            celle2006 Newbie

            Hi rkiran81,

            i think the problem is that you cannot use the @GeneratedValue Tag as you do. The oracle database usually works with sequences to create IDs. You can use these Sequences with ejb, too.

            Just add the following to your RolesProfileBean EJB.

            @Entity
            @SequenceGenerator(name="sequenceName",
            sequenceName="sequenceNameInDatabase")

            and to your ID Column:
            @GeneratedValue(strategy=GenerationType.SEQUENCE
            ,generator="sequenceName")

            Greetz celle2006

            • 3. Re: @GeneratedValue(strategy=GenerationType.AUTO) for oracle
              Oskar Carlstedt Novice

              Hi!

              I haven not read all posts but I know the following works with Oracle.

              1. Annotate your entity with @Entity as normal.

              2. Annotate your ID column with @Id. @GeneratedValue(strategy=GenerattionType.AUTO, generator="seqMyObject"), @SequenceGenerator(name="seqMyObject", sequenceMame="SEQ_MY_OBJECT")

              
              @Entity
              public class MyObject {
              
               @Id
               @GeneratedValue(strategy=GenerationType.AUTO, generator="seqMyObject")
               @SequenceGenerator(name="seqMyObject", sequenceName="SEQ_MY_OBJECT")
               private Long id;
              
               ...
              
              }
              
              


              This shall work. As previous posts said it shall also be possible to put the sequenceGenerator annotation in the class but in my point of view it looks better to put it on the id property.



              Cheers,
              Oskar