5 Replies Latest reply on May 24, 2005 3:31 PM by Victor Bonafe

    xdoclet and simple primary key

    Sven Buchwald Newbie

      I tried to create a bean with a simple primary key (Integer) but i get the exception appended creating a new instance.

      I used the pk tag to specyfy the PK-class.
      @ejb:pk class="java.lang.Integer"

      The PK-property is marked by the pk-field tag.
      /**
      * Retrieve the Article Bean's id.
      *
      * @ejb:interface-method view-type="remote"
      *
      * @return Returns an int representing the id of this TestEntity.
      *
      * @ejb:persistent-field
      * @ejb:pk-field
      *
      * @jboss:column-name name="ArticleID"
      *
      **/
      public abstract Integer getID_Article();

      What is missing?

      Thanks
      Sven


      12:05:08,051 INFO [MainDeployer] Successfully completed deployment of package: file:/D:/Programme/jboss-3.0.0/server/default/conf/jboss-service.xml
      12:05:08,051 INFO [Server] JBoss (MX MicroKernel) [3.0.0 Date:200205311035] Started in 0m:21s:501ms
      12:25:51,780 ERROR [test/SbartinfBean] Error checking if entity exists
      java.sql.SQLException: Unexpected token: in statement [SELECT COUNT(*) FROM ARTICLETABLE WHERE ]
      at org.hsqldb.Trace.getError(Trace.java:180)
      at org.hsqldb.Result.(Result.java:175)
      at org.hsqldb.jdbcConnection.executeHSQL(jdbcConnection.java:907)
      at org.hsqldb.jdbcConnection.execute(jdbcConnection.java:718)
      at org.hsqldb.jdbcStatement.fetchResult(jdbcStatement.java:686)
      at org.hsqldb.jdbcStatement.executeQuery(jdbcStatement.java:68)
      at org.hsqldb.jdbcPreparedStatement.executeQuery(jdbcPreparedStatement.java:133)
      at org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement.executeQuery(LocalPreparedStatement.java:289)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.entityExists(JDBCCreateEntityCommand.java:154)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java:127)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:450)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270)
      at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:728)
      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:324)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1116)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:257)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:134)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:44)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:104)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
      at org.jboss.ejb.Container.invoke(Container.java:726)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:362)
      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:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)

        • 1. Re: xdoclet and simple primary key
          Hans Newbie

          You must set the ejb:bean-attributes properly:

          @ejb:bean name="XXX" ... primkey-field="article"

          @ejb:pk-field is for generating compund primary keys.

          • 2. Re: xdoclet and simple primary key
            Hans Newbie

            Correction:

            @ejb:bean name="XXX" ... primkey-field="iD_ARTICLE"

            I would think about the naming of the persisten field. (perhaps getArticleId).

            • 3. Re: xdoclet and simple primary key
              Sven Buchwald Newbie

              Hallo Zuludancer, thanks for your help, but it doesn't work.

              I add your tag like this:

              * @ejb:bean name="test/SbartinfBean"
              * display-name="Article Bean to store Products in Warehouse"
              * type="CMP"
              * jndi-name="ejb/test/ArticleEJB"
              *
              * @ejb:transaction type="Required"
              *
              * @ejb:finder signature="java.util.Collection findAll()"
              *
              * @ejb:pk class="java.lang.Integer"
              *
              * @ejb:primkey-field="iD_ARTICLE"
              *
              * @jboss:table-name table-name="ArticleTable"
              *
              * @jboss:create-table create="true"
              *
              * @jboss:remove-table remove="true"
              */


              The exception from JBoss looks like this:

              10:24:04,100 ERROR [EjbModule] Starting failed
              org.jboss.deployment.DeploymentException: Error while creating table; - nested throwable: (java.sql.SQLException: Column not found: ) in statement [CREATE TABLE ARTICLETABLE (iD_ARTICLE INTEGER, Description VARCHAR(256), Amount INTEGER NOT NULL, CONSTRAINT PK_ARTICLETABLE PRIMARY KEY ())])
              at org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.createTable(JDBCStartCommand.java:190)
              at org.jboss.ejb.plugins.cmp.jdbc.JDBCStartCommand.execute(JDBCStartCommand.java:84)
              at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:383)
              at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:198)
              at org.jboss.ejb.EntityContainer.start(EntityContainer.java:376)
              at org.jboss.ejb.Container.invoke(Container.java:793)
              at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
              at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:894)
              at $Proxy6.start(Unknown Source)
              at org.jboss.system.ServiceController.start(ServiceController.java:340)
              at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:324)
              at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
              at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
              at $Proxy358.start(Unknown Source)
              at org.jboss.ejb.EjbModule.startService(EjbModule.java:440)
              at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:162)
              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:324)
              at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
              at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:894)
              at $Proxy6.start(Unknown Source)
              at org.jboss.system.ServiceController.start(ServiceController.java:340)
              at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:324)
              at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
              at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
              at $Proxy5.start(Unknown Source)
              at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:398)
              at org.jboss.deployment.MainDeployer.start(MainDeployer.java:678)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:513)
              at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:481)
              at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:324)
              at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
              at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
              at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
              at $Proxy4.deploy(Unknown Source)
              at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:405)
              at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:515)
              at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:202)
              at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:191)


              At last, here is my ejb-jar.xml:

              <ejb-name>test/SbartinfBean</ejb-name>

              test.interfaces.SbartinfBeanHome
              test.interfaces.SbartinfBean

              <ejb-class>test.entity.SbartinfBeanCMP</ejb-class>
              <persistence-type>Container</persistence-type>
              <prim-key-class>java.lang.Integer</prim-key-class>
              False
              <cmp-version>2.x</cmp-version>
              <abstract-schema-name>test/SbartinfBean</abstract-schema-name>
              <cmp-field >
              <![CDATA[Retrieve the Article Bean's id.]]>
              <field-name>iD_Article</field-name>
              </cmp-field>
              <cmp-field >
              <![CDATA[Retrieve the Article's Description.]]>
              <field-name>description</field-name>
              </cmp-field>
              <cmp-field >
              <![CDATA[Retrieve the Article Beans amount.]]>
              <field-name>amount</field-name>
              </cmp-field>



              Hope you can help me.

              • 4. Re: xdoclet and simple primary key
                Zhiyong Li Newbie

                Have anyone solved this problem? Please share your solution. I have the similar problem.

                Thanks,
                Zhiyong

                • 5. Re: xdoclet and simple primary key
                  Victor Bonafe Newbie

                  try this:

                  * @ejb:bean name="test/SbartinfBean"
                  * display-name="Article Bean to store Products in Warehouse"
                  * type="CMP"
                  * jndi-name="ejb/test/ArticleEJB"
                  * primkey-field="iD_ARTICLE"
                  *
                  * @ejb:transaction type="Required"
                  *
                  * @ejb:finder signature="java.util.Collection findAll()"
                  *
                  * @ejb:pk class="java.lang.Integer"
                  *
                  * @jboss:table-name table-name="ArticleTable"
                  *
                  * @jboss:create-table create="true"
                  *
                  * @jboss:remove-table remove="true"
                  */