7 Replies Latest reply on Mar 4, 2003 10:21 AM by milasx

    Autogenerated PK and Transactions

    milasx

      Hi,

      I have an entity bean with an auto generated pk MDSId. I have this code inside a session bean facade (with Transaction type required) for an Entity Bean :
      try
      {
      home = this.getMDSKeyVectorLocalHome();
      MDSKeyVectorLocal mdsKeyLocal =
      home.createWithMandatoryParameters(className,
      currency,
      instance,
      process);
      return mdsKeyLocal.getMDSKeyVectorValue();
      }
      MDSKeyVectorLocal has an auto generate key. I tried to put Transaction Attribute to RequiresNew and required for the createMethod but i always get an Exception:
      16:17:56,954 ERROR [LogInterceptor] TransactionRolledbackLocalException, causedBy:
      java.lang.ClassCastException
      at com.db.jbozz.ejb.entity.mds.MDSKeyVectorCMP$Proxy.getMDSId()
      at com.db.jbozz.ejb.entity.mds.MDSKeyVectorCMP.getMDSKeyVectorValue(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      Any idea?

      Thanks!

      Simone

        • 1. Re: Autogenerated PK and Transactions
          aloubyansky

          ClassCastException...
          What is the type of MDSId?
          What is the type of the value generated by the db?
          How the MDSId is mapped?

          • 2. Re: Autogenerated PK and Transactions
            milasx

            Thanks Alex,
            I see what you are saying but ...
            mDSId is Long and the identity column (mDSId) is NUMERIC (8). In my standardjbosscmp the mapping is:

            <java-type>java.lang.Long</java-type>
            <jdbc-type>NUMERIC</jdbc-type>
            <sql-type>NUMERIC(38,0)</sql-type>
            .

            I also tried to add on my jbosscmp-jdbc.xml
            <field-name>mDSId</field-name>
            <column-name>MV_MDS_ID</column-name>

            <jdbc-type>NUMERIC</jdbc-type>
            <sql-type>NUMERIC(8)</sql-type>
            but get a nasty warning @ deploy time:
            13:46:08,123 WARN [JDBCMappingMetaData] Unrecognized jdbc-type: type type="NUMERIC", using Types.OTHER
            java.lang.NoSuchFieldException: type type="NUMERIC"
            at java.lang.Class.getField0(Class.java:1735)
            at java.lang.Class.getField(Class.java:900)
            at org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCMappingMetaData.getJdbcTypeFromName(JDBCMappingMetaData.java:41)

            Any idea?

            Simone

            • 3. Re: Autogenerated PK and Transactions
              milasx

              Hi Alex,

              Apologies, forget the part about the last Exception, that was a typo in my XDoclet tags.
              *@jboss.sql-type type type="NUMERIC"
              Oooops :) Thanks to your hint I also solved the issue of the ClassCastException! The problem was on JDBCCreateEntityCommand for Sybase that I made that was doing:
              JDBCCMPFieldBridge cmpField = (JDBCCMPFieldBridge)iter.next();
              cmpField.setInstanceValue(ctx, pk);
              where pk was an Object as opposed to Long. Shall I update the patch I made for Sybase?

              Thanks!

              Simone

              • 4. Re: Autogenerated PK and Transactions
                aloubyansky

                Yes, please, update the patch.
                I didn't get the exact reason of failure though.

                alex

                • 5. Re: Autogenerated PK and Transactions
                  milasx

                  cmpField.setInstanceValue(ctx, pk);
                  pk vas type Object in the plugin code but actually on my bean is declared to be Long therefore the ClassCastException.
                  I will update the patch.

                  Simone

                  • 6. Re: Autogenerated PK and Transactions
                    zampetti

                    I too am working to enable auto-incremented keys in Sybase. Did someone already get this working?

                    • 7. Re: Autogenerated PK and Transactions
                      milasx