1 Reply Latest reply on Mar 16, 2003 8:58 PM by Adrian Brock

    Encounter  TransactionRolledbackLocalException  ( simple loc

    sachinsisodia Newbie

      hello guys
      i m new for the ejb and i m trying to run a simple local interface bean program.


      where there are one local entity bean, and i call that bean from an another session bean.

      here is my code:

      // LocalUser3.java
      package user;
      public interface LocalUser3 extends javax.ejb.EJBLocalObject {

      public String getEmail();
      public String getPassword();
      public void setEmail(String email);
      public void setPassword(String email);

      }

      //LocalUser3Home.java

      package user;

      import javax.ejb.CreateException;
      import javax.ejb.FinderException;

      import java.util.Collection;

      public interface LocalUser3Home extends javax.ejb.EJBLocalHome {

      public LocalUser3 create( String email, String password
      )
      throws CreateException;

      }
      //User3EJB.java
      package user;

      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Iterator;
      import javax.ejb.CreateException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.naming.Context;
      import javax.naming.InitialContext;

      public abstract class User3EJB implements EntityBean {

      public abstract String getEmail();
      public abstract String getPassword();
      public abstract void setEmail( String email);
      public abstract void setPassword(String password);


      public String ejbCreate (
      String email,
      String password)
      throws CreateException {
      setEmail(email);
      setPassword(password);
      return null;
      }

      public void ejbPostCreate (
      String email,
      String password)
      throws CreateException { }

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

      }
      public void unsetEntityContext() {

      this.ctx = null;

      }

      public void ejbRemove() { }
      public void ejbLoad() { }
      public void ejbStore() { }
      public void ejbPassivate(){
      setEmail(null);
      setPassword(null);
      }

      public void ejbActivate() { }


      }

      // session bean
      //UserManagementHome

      package user;

      import javax.ejb.*;
      import java.rmi.*;

      public interface UserManagementHome extends javax.ejb.EJBHome {
      UserManagement create() throws java.rmi.RemoteException,
      javax.ejb.CreateException;

      }
      package user;

      //UserManagement.java

      import javax.ejb.*;
      import java.rmi.*;
      public interface UserManagement extends javax.ejb.EJBObject {

      public void addUser(String email, String password) throws
      RemoteException;
      }


      //UserManagementEJB .java
      package user;

      import java.util.ArrayList;
      import java.util.Collection;
      import java.util.Iterator;
      import javax.ejb.CreateException;

      import javax.naming.Context;
      import javax.naming.InitialContext;

      import javax.ejb.*;
      import javax.naming.*;
      import java.rmi.*;
      import javax.rmi.*;

      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import javax.ejb.*;
      import java.rmi.*;
      import javax.naming.*;
      import java.util.*;


      public class UserManagementEJB implements SessionBean {

      public void addUser(String email, String password){
      try {
      InitialContext ctx= null;
      ctx =new InitialContext();


      LocalUser3Home user = (LocalUser3Home) ctx.lookup
      ( "java:comp/env/ejb/User3" );

      LocalUser3 user1 = user.create(email, password);

      } catch (CreateException e) {
      throw new EJBException();
      }
      catch (Exception ex) {
      ex.printStackTrace();
      }


      }



      public void setSessionContext( javax.ejb.SessionContext
      ejbSessionContext )
      throws RemoteException
      {
      }

      public void unsetSessionContext()
      throws RemoteException
      {
      }

      public void ejbRemove()
      throws java.rmi.RemoteException, javax.ejb.EJBException
      {
      }

      public void ejbActivate()
      throws java.rmi.RemoteException
      {
      }

      public void ejbPassivate()
      throws java.rmi.RemoteException
      {
      }

      public void ejbCreate() throws java.rmi.RemoteException {}



      }


      //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">
      <ejb-jar>

      <enterprise-beans>


      <ejb-name>UserManagement</ejb-name>
      user.UserManagementHome
      user.UserManagement
      <ejb-class>user.UserManagementEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <ejb-local-ref>
      <ejb-ref-name>ejb/User3</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>user.LocalUser3Home</local-home>
      user.LocalUser3
      <ejb-link>User3</ejb-link>
      </ejb-local-ref>



      <display-name>User3EJB</display-name>
      <ejb-name>User3</ejb-name>

      <local-home>user.LocalUser3Home</local-home>
      user.LocalUser3
      <ejb-class>user.User3EJB</ejb-class>

      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>

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

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

      <cmp-field>
      <field-name>email</field-name>
      </cmp-field>

      <cmp-field>
      <field-name>password</field-name>
      </cmp-field>

      <primkey-field>email</primkey-field>

      </enterprise-beans>

      </ejb-jar>
      //jbosscmp-jdbc.xml

      <?xml version = "1.0" encoding = "UTF-8"?>


      <enterprise-beans>



      <ejb-name>User3</ejb-name>
      <table-name>User3</table-name>
      <cmp-field>
      <field-name>email</field-name>
      <column-name>password</column-name>
      <jdbc-type>VARCHAR</jdbc-type>
      <sql-type>VARCHAR(64)</sql-type>
      </cmp-field>




      </enterprise-beans>

      //jboss.xml



      <enterprise-beans>



      <ejb-name>UserManagement</ejb-name>
      <jndi-name>UserManagement</jndi-name>

      </enterprise-beans>





      Now i m trying to invoke this session bean from my client program that
      further communicate with local entity bean.Both session and entity bean
      in one jar.

      Bt doing so i encounter a tranctionrollback exception which i mentioned
      earlier

      plz help me how to slove it ,i m wrong somewhere, or i miss something

      thanx in advance

      cheers
      sachin