9 Replies Latest reply on Mar 26, 2002 1:00 PM by dward2

    Primary Key problem in XML file?

    ericjee

      Can somebody tell me what is wrong with this, Is it my xml file that is doing this? It gives me this problem when I am using java.lang.Integer as a Primary Key type,

      [03:17:58,615,ContainerFactory] Could not deploy file:/E:/programming/java/jboss
      /jboss-3.0.0alpha/deploy/Default/XMLInsider.jar/
      org.jboss.ejb.DeploymentException: primkey-field must be the same type as prim-k
      ey-class
      at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCCMPFieldMetaData.........


      <display-name>User</display-name>
      <ejb-name>User</ejb-name>
      UserHome
      User
      <ejb-class>UserBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      <primkey-field>PKUserId</primkey-field>
      True
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>User</abstract-schema-name>
      <cmp-field>
      <field-name>PKUserId</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>UserName</field-name>
      </cmp-field>


      If I change the PK to anything that is a String (like username) , and change the type to string, it deploys without throwing the error(excluding the fact that I have to comment out the EJBQL). Is it something to do with my jbosscmp-jdbc file? How does jboss know what is the datatype of pkuserid in the first place? Is it possible that this is my jdk's fault? (jdk1.4beta3, running jboss3.0.0alpha)

      Somebody please help,

      Eric

        • 1. Re: Primary Key problem in XML file?
          armint

          The <primkey-field> element should go after the last <cmp-field>

          • 2. Re: Primary Key problem in XML file?
            ericjee

            It was there before originally and it threw the exception, i moved it up for clarity. The placement is not the reason.


            ie


            <display-name>User</display-name>
            <ejb-name>User</ejb-name>
            UserHome
            User
            <ejb-class>UserBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.Integer</prim-key-class>
            True
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>User</abstract-schema-name>
            <cmp-field>
            <field-name>PKUserId</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>UserName</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>Password</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>AccountStatus</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>ExpirationDate</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>LockDate</field-name>
            </cmp-field>
            <primkey-field>PKUserId</primkey-field>
            .....

            still throws the error.


            Any other thoughts, please?
            Thanks, eric

            • 3. Re: Primary Key problem in XML file?
              armint

              How does jboss know what is the datatype of pkuserid in the first place?

              I bet it checks the bean implementation. In your case, it will look at:

              public abstract Integer getPKUserId();
              public abstract void setPKUserId(Integer value);

              • 4. Re: Primary Key problem in XML file?
                ericjee

                I thought the same, but in numerous examples on the internet you can supply a
                abstract int getsomething()
                and a
                abstract void setsomething(int value)

                and use the key value java.lang.Integer in the XML file. So I did the same, I thought they just matched up by the containter since Integer is a wrapper for an int object.

                ie

                public abstract class JudgeBean implements EntityBean {

                public abstract int getJudgeId();
                public abstract void setJudgeId(int judgeId);

                has xml dd file...

                <ejb-jar>
                <display-name>judge_case</display-name>
                <enterprise-beans>

                <display-name>JudgeEJB</display-name>
                <ejb-name>JudgeEJB</ejb-name>
                examples.judge_case.JudgeHome
                examples.judge_case.Judge
                <ejb-class>examples.judge_case.JudgeBean</ejb-class>
                <persistence-type>Container</persistence-type>
                <prim-key-class>java.lang.Integer</prim-key-class>
                True
                <cmp-version>2.x</cmp-version>
                <abstract-schema-name>JudgeBean</abstract-schema-name>
                <cmp-field><field-name>judgeName</field-name></cmp-field>
                <cmp-field><field-name>judgeId</field-name></cmp-field>
                <primkey-field>judgeId</primkey-field>



                Any more help? This should work the way I'm doing it, and I do not want to change my return type to Integer, it just wouldn't make sense according to numerous online examples.

                Eric

                • 5. Re: Primary Key problem in XML file?
                  ericjee

                  So basically what I'm trying to say in the last post is that it still doesnt work even though its supposed to. Somebody please help! I don't understand why it thinks that PKUserId, which is type int, and is delared as <primkey-field>, is not the same type as java.lang.Integer. What else could be possibly wrong!!!!!

                  • 6. Re: Primary Key problem in XML file?
                    greathavoc

                    I'm currently using JBoss 3 Alpha and I'm having the same problem. It seems that we can't use a Java primitive as the primary key in the bean implementation, for JBoss that is. I did not find the same problem with J2EE RI. Maybe it's a bug in JBoss? Anyone got any ideas?

                    • 7. Re: Primary Key problem in XML file?
                      dsundstrom

                      A primary key can not be a primative. It is in the EJB 2.0 spec section 9.8.

                      • 8. Re: Primary Key problem in XML file?
                        roysun

                        Comparing ejb spec 1.1 and 2.0, they are almost same. They do not clearly say that "primary key must not be a primitive type".

                        But 1.1 supports primitive type as a primary key for sure.

                        Roy

                        • 9. Re: Primary Key problem in XML file?

                          A better place in the ejb2.0 spec is section 10.5.2, at the bullet called "public PrimaryKeyClass ejbCreate(...);"

                          Though is shows that cmp fields can be primitive (looking at it's 0 default for integer primitive), it does say in the second to last paragraph of the bullet that (for CMP), "The implementation of the Bean Provider's ejbCreate(...) methods should be coded to return a null." Obviously, this means you can't define your return type as a primitive.