3 Replies Latest reply on Jul 4, 2002 5:07 PM by dsundstrom

    Internal error setting instance field

    sarojk_singh

      Hi All,

      I am getting a nasty exception while trying to insert a new record using JBOSS 3 and CMP2.0.

      Exception is :

      Caused by: java.rmi.ServerException: Internal error setting instance field customerId
      Embedded Exception
      CustomerPK; nested exception is:
      javax.ejb.EJBException: Internal error setting instance field customerId

      I have written a Simple CustomerBean with 2 fields , customerId and customerName. When i call create method on home interface, i get above error on my client side. Server SIDE does not give any probs.

      Please help me.

      TIA,
      Saroj

        • 1. Re: Internal error setting instance field
          dsundstrom

          What is the exception you are getting in the server.log file on the server side?

          This is usually caused by either a bad custom pk (they are very difficult to code correctly) or trying to load an existing table with null values in the pk column, which is not allowed by the SQL spec.

          My guess the customerId field has the wrong capitolization or it is not public.

          • 2. Re: Internal error setting instance field
            sarojk_singh

            Hi Dan,

            I have tried to check my code but still same error is there.

            ************************************
            See the Primary KEy class (CustomPK)
            *************************************

            import java.io.*;

            public class CustomerPK implements java.io.Serializable
            {
            public String customerId ;

            public CustomerPK(String customerId)
            {
            this.customerId = customerId;
            }

            public String toString()
            {
            return customerId.toString();
            }

            public int HashCode()
            {
            return customerId.hashCode();
            }

            public boolean equals(Object cust)
            {
            return ((CustomerPK)cust).customerId.equals(this.customerId);
            }
            }

            ****************************************
            EJB-JAR.XML
            ****************************************
            <ejb-class>CustomerBean</ejb-class>

            <persistence-type>Container</persistence-type>

            <prim-key-class>CustomerPK</prim-key-class>

            <!-- prim-key-class>java.lang.String</prim-key-class -->
            False

            <cmp-version>2.x</cmp-version>

            <abstract-schema-name>CustomerBean</abstract-schema-name>

            <cmp-field>
            <field-name>customerId</field-name>
            </cmp-field>

            <cmp-field>
            <field-name>customerName</field-name>
            </cmp-field>

            <!-- primkey-field>customerId</primkey-field -->

            *********************
            Error Trace
            *********************
            client:
            [java] Getting Initial Context
            [java] -----------------------------------------------------------
            [java] Going to create the Record
            [java] java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
            [java] Caught an unexpected exception while making contract!
            [java] java.rmi.ServerException: Internal error setting instance field customerId
            [java] Embedded Exception
            [java] CustomerPK; nested exception is:
            [java] javax.ejb.EJBException: Internal error setting instance field customerId
            [java] Embedded Exception
            [java] CustomerPK
            [java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
            [java] at sun.rmi.transport.Transport$1.run(Transport.java:148)
            [java] at java.security.AccessController.doPrivileged(Native Method)
            [java] at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
            [java] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
            [java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
            [java] at java.lang.Thread.run(Thread.java:536)
            [java] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
            [java] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
            [java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
            [java] at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
            [java] at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:128)
            [java] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:108)
            [java] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73)
            [java] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76)
            [java] at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:185)
            [java] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
            [java] at $Proxy0.create(Unknown Source)
            [java] at test_ejbs.make_Customer(test_ejbs.java:98)
            [java] at test_ejbs.(test_ejbs.java:61)
            [java] at test_ejbs.main(test_ejbs.java:140)
            [java] Caused by: java.rmi.ServerException: Internal error setting instance field customerId
            [java] Embedded Exception
            [java] CustomerPK; nested exception is:
            [java] javax.ejb.EJBException: Internal error setting instance field customerId
            [java] Embedded Exception
            [java] CustomerPK
            [java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:119)
            [java] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
            [java] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
            [java] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:104)
            [java] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109)
            [java] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
            [java] at org.jboss.ejb.Container.invoke(Container.java:726)
            [java] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
            [java] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
            [java] at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:362)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            [java] at java.lang.reflect.Method.invoke(Method.java:324)
            [java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
            [java] at sun.rmi.transport.Transport$1.run(Transport.java:148)
            [java] at java.security.AccessController.doPrivileged(Native Method)
            [java] at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
            [java] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
            [java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
            [java] at java.lang.Thread.run(Thread.java:536)
            [java] Caused by: javax.ejb.EJBException: Internal error setting instance field customerId
            [java] Embedded Exception
            [java] CustomerPK
            [java] at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setPrimaryKeyValue(JDBCAbstractCMPFieldBr
            idge.java:219)
            [java] at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.extractPrimaryKeyFromInstance(JDBCEntityBridge.java
            :556)
            [java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java:124)
            [java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:450)
            [java] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253)
            [java] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.
            java:270)
            [java] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:728)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            [java] at java.lang.reflect.Method.invoke(Method.java:324)
            [java] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1116)
            [java] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
            [java] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:25
            7)
            [java] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.ja
            va:215)
            [java] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:134)
            [java] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
            [java] at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:44)
            [java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
            [java] ... 20 more

            • 3. Re: Internal error setting instance field
              dsundstrom

              Your primary key class does not have a default constructor. Add a no-argument constructor and it should start working. As I said it is very difficult to correctly code a pk class.

              BTW you equals code should be: [pre]
              public boolean equals(Object obj) {
              if (obj instanceof CustomerPK) {
              CustomerPK c = (CustomerPK)obj;
              if (c.customerId == null) {
              return customerId == null;
              }
              return c.customerId.equals(customerId);
              }
              return false;
              }
              [/pre]