0 Replies Latest reply on Sep 26, 2001 4:42 PM by Barnali Dey

    Transaction Rollback Exception. Please Help!

    Barnali Dey Newbie

      I am trying to deploy & test one cmp entity bean in JBOSS. It seems the ejb is deployed properly & successfully. But while running the client it's giving transaction rollback exception.
      Could anyone please help me in solving this problem?

      Thanks in advance for your help..

      My codes are as follows

      +++++++++++++++++++ HOME Interface ++++++++++++++++++

      package org.jboss.docs.testJboss.interfaces;

      import javax.ejb.EJBHome;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import java.rmi.RemoteException;
      import java.util.Collection;

      public interface TestHome
      extends EJBHome
      public Test create(final int id, final String name)
      throws CreateException, RemoteException;
      public Test findByPrimaryKey(final int id)
      throws FinderException, RemoteException;


      +++++++++++++++++++ REMOTE Interface ++++++++++++++++++

      package org.jboss.docs.testJboss.interfaces;

      import javax.ejb.EJBObject;
      import java.rmi.RemoteException;

      public interface Test
      extends EJBObject

      public void add() throws RemoteException;

      public int getId() throws RemoteException;
      public void setId(int id) throws RemoteException;

      public String getName() throws RemoteException;;
      public void setName(String name) throws

      +++++++++++++++++++ BEAN +++++++++++++++++++++++++++

      package org.jboss.docs.testJboss.bean;

      import org.jboss.docs.testJboss.interfaces.*;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;

      * Entity Bean representing a Class. A Class have a Teacher and a number of
      * Students

      public class TestBean
      implements EntityBean
      EntityContext ctx;

      private int id;
      private String name;

      * Create an instance of a Class.
      public int ejbCreate (final int id, final String name)
      this.id = id;
      this.name = name;
      return 0;

      public void ejbPostCreate(final int id, final String name) { }

      public int getId()
      return id;
      public void setId( int newId)
      id = newId;

      public String getName()
      return name;
      public void setName( String newName)
      name = newName;

      public void add()
      setId( id );
      setName( name );

      public void setEntityContext(EntityContext ctx) { this.ctx = ctx; }

      public void unsetEntityContext() { ctx = null; }

      public void ejbActivate() {}

      public void ejbPassivate()


      public void ejbLoad()


      public void ejbStore() { }
      public void ejbRemove() { }


      ++++++++++++++++ jaws.xml +++++++++++++++++++++++







      ++++++++++++++++++++++++ JBOSS.xml +++++++++++++++
      <?xml version="1.0" encoding="Cp1252"?>

      <container-configurations />
      <resource-managers />



      +++++++++++++++++++ ejb-jar.xml ++++++++++++++++

      <?xml version="1.0"?>

      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">


      Testing JBOSS






      ++++++++++++++++++ CLIENT src file (Upload.java) ++++++

      package org.jboss.docs.testJboss;

      import org.jboss.docs.testJboss.interfaces.TestHome;
      import org.jboss.docs.testJboss.interfaces.Test;

      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;

      import java.util.Hashtable;
      import java.util.StringTokenizer;
      import java.util.Properties;
      import java.io.FileInputStream;

      * Uploads a tab-delimited file of CD data to the database. There is a `main()'
      * method so this class can be run from the command line. `main()' takes one
      * command-line argument: the name of the file to upload. See the documentation
      * for the `uploadFile()' method for details of the file format. Note that the
      * uploading process may be very slow on some machines, especially if you are
      * using an interpreting JVM. Expect to have a cup of coffee if you are
      * uploading more than a hundred CDs.
      * Note that the uploadFile method deletes the existing database before it
      * uploads.
      public class Upload

      * Run the upload process from the command line.
      public static void main(String[] args)
      String name = "Testing JBOSS";
      int id = 10;

      System.out.println("1. Value of ID is = " +id);
      System.out.println("1. Value of name is =" +name);

      uploadValue (id, name);

      catch(Exception e)
      System.err.println("ERROR: " + e.toString());
      System.out.println ("OK");

      * This method uploads a database of CDs specified as a text file. The file
      * must contain one line for each CD, with 5 fields on each line. The
      * ordering of the fields is id-title-artist-type-notes. The fields are
      * separated with tabs. Note that a tab on its own must exist as a
      * placeholder for an empty field.
      public static void uploadValue (int id, String name)
      throws javax.naming.NamingException,
      java.rmi.RemoteException, javax.ejb.CreateException

      // Get a naming context
      InitialContext jndiContext = new InitialContext();

      // Get a reference to a CD Bean
      Object ref = jndiContext.lookup("testJboss/Test");

      // Get a reference from this to the Bean's Home interface
      TestHome home = (TestHome)
      PortableRemoteObject.narrow (ref, TestHome.class);

      System.out.println("2. Value of ID is = " +id);
      System.out.println("2. Value of name is =" +name);

      Test test = home.create(id, name);

      System.out.println("3. Value of ID is = " +id);
      System.out.println("3. Value of name is =" +name);


      } // End of uploadFile()


      +++++++++++++++++++++++ build-client.xml ++++++++++

      <?xml version="1.0" encoding="UTF-8" ?>
      <!-- An Ant build file for the CMP tutorial code -->

      +++++++++++++++++++ build-testJboss-compile +++++++++
      <?xml version="1.0" encoding="UTF-8" ?>
      <!-- An Ant build file for the CMP tutorial code -->

      <!-- JNDI Client used to connect to JBoss running on localhost -->

      <!-- File containing some cds -->


      ++++++++++++++++ ERROR MESSAGE both in JBOSS server console & command prompt +++++++++++++++++

      Message displayed in the JBOSS console after copying the test.jar in the deploy directory :

      [AutoDeployer] Auto deploy of file:/C:/JBoss-2.4.0/deploy/Test.jar
      [J2EE Deployer Default] Deploy J2EE application: file:/C:/JBoss-2.4.0/deploy/Test.jar
      [J2eeDeployer] Create application Test.jar
      [J2eeDeployer] install EJB module Test.jar
      [Container factory] Deploying:file:/C:/JBoss-2.4.0/tmp/deploy/Default/Test.jar
      [Verifier] Verifying file:/C:/JBoss-2.4.0/tmp/deploy/Default/Test.jar/ejb1001.jar
      Bean : TestBean
      Method : public int ejbCreate(int, String)
      Section: 9.2.3
      Warning: The return type of an ejbCreate(...) method must be the entity bean's primary key type.

      Bean : TestBean
      Warning: The primkey-field element must name a public field in the bean implementation class.

      [Container factory] Deploying TestBean
      [JAWS] Created table 'TEST' successfully.
      [Default] null
      [Bean Cache] Cache policy scheduler started
      [ContainerManagement] Initializing
      [ContainerManagement] Initialized
      [ContainerManagement] Starting
      [ContainerManagement] Started
      [Container factory] Deployed application: file:/C:/JBoss-2.4.0/tmp/deploy/Default/Test.jar
      [J2EE Deployer Default] J2EE application: file:/C:/JBoss-2.4.0/deploy/Test.jar is deployed.

      Message displayed in the JBOSS console after running the client from the command prompt :

      [TestBean] TRANSACTION ROLLBACK EXCEPTION:null; nested exception is:
      [TestBean] java.lang.NullPointerException
      [TestBean] at org.jboss.ejb.plugins.jaws.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityC
      [TestBean] at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.createEntity(JAWSPersistenceMan
      [TestBean] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.ja
      [TestBean] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:538)
      [TestBean] at java.lang.reflect.Method.invoke(Native Method)
      [TestBean] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.jav
      [TestBean] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchroni
      [TestBean] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceIntercep
      [TestBean] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:135)
      [TestBean] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:
      [TestBean] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
      [TestBean] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:103
      [TestBean] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:106)
      [TestBean] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:342)
      [TestBean] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerIn
      [TestBean] at java.lang.reflect.Method.invoke(Native Method)
      [TestBean] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
      [TestBean] at sun.rmi.transport.Transport$1.run(Transport.java:142)
      [TestBean] at java.security.AccessController.doPrivileged(Native Method)
      [TestBean] at sun.rmi.transport.Transport.serviceCall(Transport.java:139)
      [TestBean] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:443)
      [TestBean] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:643)
      [TestBean] at java.lang.Thread.run(Thread.java:484)

      Message displayed in the command prompt after running the client :

      C:\JBoss-2.4.0\examples\build>ant cmp-testJboss-upload
      Buildfile: build.xml



      [echo] Using JBoss directory=C:/JBoss-2.4.0
      [echo] Using base classpath=C:\JBoss-2.4.0\client\jboss-j2ee.jar;C:\JBoss-2
      [echo] Using Source directory=C:\JBoss-2.4.0\examples
      [echo] Using Build directory=C:\JBoss-2.4.0\examples/build-examples


      [java] 1. Value of ID is = 10
      [java] 1. Value of name is =Testing JBOSS
      [java] 2. Value of ID is = 10
      [java] 2. Value of name is =Testing JBOSS
      [java] ERROR: java.rmi.ServerException: RemoteException occurred in server
      thread; nested exception is:
      [java] OK
      [java] javax.transaction.TransactionRolledbackException: null; nested e
      xception is:
      [java] javax.ejb.EJBException


      Total time: 12 seconds