5 Replies Latest reply on Jan 17, 2003 6:25 AM by Hans Bausewein

    java.lang.Long primary key and Postgres

    Hans Bausewein Newbie

      If I use
      @ejb:pk class="java.lang.Long"
      in my CMP entity bean instead of the default primary key, I get a

      DeploymentException: Error while creating table; -
      nested throwable: (java.sql.SQLException:
      ERROR: parser: parse error at or near ")"

      The only difference in the generated XML is the
      <prim-key-class>java.lang.Long</prim-key-class>
      in 'ejb-jar.xml' for the entity.

      If I read the J2EE CMP specification well, it's quite legal to use
      'java.lang.Long' as primary key class instead of a wrapped EjbPK class.

      Is this a bug in JBoss or maybe in the Postgres definition ?

      I guess it happens when a diffent PK must be inserted in the 'CREATE
      TABLE' sql.


      versions:
      JBoss 3.0.4
      JDK 1.4.1
      OS: linux 2.4.17


      Hans

        • 1. Re: java.lang.Long primary key and Postgres
          Loren Rosen Newbie

          I have Long keys working Postgres. Can you try running postmaster with the -d 2 flag so we can see precisely the SQL that it doesn't like?

          • 2. Re: java.lang.Long primary key and Postgres
            Hans Bausewein Newbie

            > I have Long keys working Postgres. Can you try
            > running postmaster with the -d 2 flag so we can see
            > precisely the SQL that it doesn't like?

            this is the primary key part:
            CONSTRAINT pk_myprimarykey PRIMARY KEY ())

            exactly what I thought: the key field name is missing.

            The type of the primary key field is also java.lang.Long
            but of course the EjbClassPK class is not generated.
            I guess it cannot find the type and then fails to set the name.

            I'll try to run the example project with Postgres and Long keys.

            Hans

            • 3. Re: java.lang.Long primary key and Postgres
              Hans Bausewein Newbie

              This is the full output for the original example (*):

              DEBUG: query: CREATE TABLE testentity (Id INT4 NOT NULL, First_Name TEXT,
              Last_Name TEXT, Password TEXT, Email TEXT, Address TEXT,
              City TEXT, ZIP TEXT, State TEXT, Country TEXT, Creation_Date DATE,
              Modification_Date DATE, CONSTRAINT pk_testentity PRIMARY KEY (Id))

              NOTICE: CREATE TABLE/PRIMARY KEY will create
              implicit index 'pk_testentity' for table 'testentity'

              DEBUG: ProcessUtility: CREATE TABLE testentity (Id INT4 NOT NULL,
              First_Name TEXT, Last_Name TEXT,
              Password TEXT, Email TEXT, Address TEXT,
              City TEXT, ZIP TEXT, State TEXT, Country TEXT, Creation_Date DATE,
              Modification_Date DATE, CONSTRAINT pk_testentity PRIMARY KEY (Id))

              DEBUG: ProcessUtility: CREATE TABLE testentity (Id INT4 NOT NULL,
              First_Name TEXT, Last_Name TEXT,
              Password TEXT, Email TEXT, Address TEXT,
              City TEXT, ZIP TEXT, State TEXT, Country TEXT, Creation_Date DATE,
              Modification_Date DATE, CONSTRAINT pk_testentity PRIMARY KEY (Id))


              Then I added the tag
              @ejb:pk class="java.lang.Long"
              to src/main/ejb/test/entity/TestEntityBean.java in the jboss example.

              This is the failing SQL I get:

              CREATE TABLE testentity (Id INT4 NOT NULL,
              First_Name TEXT, Last_Name TEXT,
              Password TEXT, Email TEXT, Address TEXT,
              City TEXT, ZIP TEXT, State TEXT, Country TEXT, Creation_Date DATE,
              Modification_Date DATE, CONSTRAINT pk_testentity PRIMARY KEY ())


              You can download my modified example from:
              http://knuth.marketxs.com/~hans/jboss/jboss3example.tar.gz

              My postgres version 7.1.3

              Hans Bausewein

              (*) I've modified the example to get working xdoclet tags. See my posts on
              forum "Getting Started Documentation" in december.

              • 4. Re: java.lang.Long primary key and Postgres
                Hans Bausewein Newbie

                I've made a some small modifications to the example project:
                'TestEntityBean.java':
                - the type of id changed from 'int' to 'java.lang.Integer'
                - removed class 'TestEntityBeanPK' from the import list.
                - return type of 'ejbCreate' is now 'java.lang.Integer'
                'SequenceGeneratorBean':
                - uses Postgres instead of Hypersonic

                The xdoclet tag to add is:
                @ejb:pk class="java.lang.Integer"

                Check the date and size of 'TestEntityBean.java':
                15725 Jan 17 11:26 TestEntityBean.java


                To run the example, you need to create a sequence in Postgres:
                CREATE SEQUENCE SeqTestEntity;

                to test it:
                SELECT Nextval( 'SeqTestEntity' );


                Hans

                • 5. Re: java.lang.Long primary key and Postgres - FIXED :-)
                  Hans Bausewein Newbie

                  Found the problem :-)


                  Add to '@ejb:bean' tag this attribute: primkey-field="Id"

                  This adds the extra
                  <primkey-field>Id</primkey-field>
                  to the bean's entity in 'ejb-jar.xml'

                  I've also found some xdoclet documentation:
                  http://xdoclet.sourceforge.net/using.html


                  Hans