3 Replies Latest reply on Jul 28, 2005 12:44 PM by Franco

    Help stuck with JBoss 4.0.2 and MySQL 4.1.13

    Sameer Saptarishi Newbie

      Hi All,
      I have a HospitalBean which is called from a HospitalManagerBean which is a SessionBean.

      The Manager code is as follows
      public HospitalData addHospital(HospitalData hospitalData) throws EJBException,RemoteException{
      HospitalData newHospitalData = new HospitalData();

      try {
      System.out.println("Debug in HospitalManager 1********");
      InitialContext initialContext = new InitialContext();
      System.out.println("Debug in HospitalManager 2********");
      HospitalHome hospitalHome = (HospitalHome) initialContext.lookup(JNDINames.Hospital_Home);
      System.out.println("Debug in HospitalManager 3********");
      Hospital hospital = hospitalHome.create(hospitalData);
      System.out.println("$$$$$$$Created Hospital$$$$$$$$$$$");
      System.out.println("Hospital Primary Key" + hospital.getPrimaryKey().toString());
      newHospitalData = hospital.getHospitalData();

      return newHospitalData;
      } catch (NamingException ne) {
      throw new EJBException(ne.getMessage());
      } catch (CreateException ce) {
      throw new EJBException(ce.getMessage());
      }
      }

      The Hospital Entity Bean is as follows
      public abstract class HospitalEJB implements EntityBean {

      private EntityContext context;
      public Long hospitalid;
      public String hospitalname;

      public void ejbLoad() throws EJBException, RemoteException {

      }
      public void ejbActivate() throws EJBException, RemoteException {

      }

      public Long ejbCreate(HospitalData hospitalData) throws CreateException{
      Long myid = new Long(UniqueIdGenerator.getId());
      System.out.println("My id generated ====== "+myid);
      this.hospitalid = myid;
      System.out.println("My id generated ====== "+this.hospitalid);
      System.out.println("Came in ejbCreate method of HospitalEJB");

      this.hospitalname = hospitalData.getHospitalname();
      return null;

      }

      public void ejbPostCreate(HospitalData hospitalData)throws CreateException,RemoteException{
      System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
      System.out.println("Came in EJB POSTCreate of HospitalEJB");
      System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");

      }

      public void ejbRemove()
      throws RemoveException, RemoteException, EJBException {

      }

      public void setEntityContext(EntityContext context)
      throws EJBException, RemoteException {

      }

      public void unsetEntityContext() throws EJBException, RemoteException {


      }

      public void ejbPassivate() throws EJBException, RemoteException {

      }

      public void ejbStore() throws EJBException, RemoteException {

      }





      /**
      * @return
      */
      public abstract Long getHospitalid();

      /**
      * @return
      */
      public abstract String getHospitalname();

      /**
      * @param long1
      */
      public abstract void setHospitalid(Long long1);

      /**
      * @param string
      */
      public abstract void setHospitalname(String string);


      public HospitalData getHospitalData(){
      System.out.println("Came in get hospital data");
      System.out.println("In Get method of HospitalEJB"+this.hospitalid);
      System.out.println("In Get method of HospitalEJB"+this.hospitalname);

      HospitalData hospitalData = new HospitalData();
      hospitalData.setHospitalid(this.hospitalid);
      hospitalData.setHospitalname(this.hospitalname);
      System.out.println("In Get method of HospitalEJB"+hospitalData.getHospitalid());
      System.out.println("In Get method of HospitalEJB"+hospitalData.getHospitalname());
      return hospitalData;
      }


      public void setHospitalData(HospitalData hospitalData){
      System.out.println("In Set method of HospitalEJB" + hospitalData.getHospitalname());
      this.hospitalname = hospitalData.getHospitalname();
      }

      }


      The bean is deployed properly.The tables are also created but when I run the application it gives the following error:

      18:27:12,093 ERROR [LogInterceptor] TransactionRolledbackException in method: public abstract com.cygnet.medina.Hospital.Hospital com.cygnet.medina.Hospital.HospitalHome.create(com.cygnet.medina.Hospital.HospitalData) throws javax.ejb.CreateException,java.rmi.RemoteException, causedBy:
      javax.ejb.EJBException: getGeneratedKeys returned an empty ResultSet
      at org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand.executeInsert(JDBCMySQLCreateCommand.java:87)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:308)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:138)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:572)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:222)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:266)
      at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:766)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)

      A 0 is entered in the hospitalid field and no value is entered in the hospital name field.

      Here is my ejb-jar.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      <enterprise-beans>

      <ejb-name>UserManager</ejb-name>
      com.cygnet.medina.UserManager.UserManagerHome
      com.cygnet.medina.UserManager.UserManager
      <ejb-class>com.cygnet.medina.UserManager.UserManagerEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      <assembly-descriptor>
      <container-transaction>

      <ejb-name>UserManager</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>



      <ejb-name>HospitalManager</ejb-name>
      com.cygnet.medina.HospitalManager.HospitalManagerHome
      com.cygnet.medina.HospitalManager.HospitalManager
      <ejb-class>com.cygnet.medina.HospitalManager.HospitalManagerEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      <assembly-descriptor>
      <container-transaction>

      <ejb-name>HospitalManager</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>


      <ejb-name>AnesthesiaUser</ejb-name>
      com.cygnet.medina.user.AnesthesiaUserHome
      com.cygnet.medina.user.AnesthesiaUser
      <ejb-class>com.cygnet.medina.user.AnesthesiaUserEJB</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>AnesthesiaUser</abstract-schema-name>
      <cmp-field>
      <field-name>userid</field-name>
      <column-name>userid</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>username</field-name>
      <column-name>username</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      <column-name>password</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>usertype</field-name>
      <column-name>usertype</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>createddate</field-name>
      <column-name>createddate</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>updateddate</field-name>
      <column-name>updateddate</column-name>
      </cmp-field>
      <primkey-field>userid</primkey-field>

      <query-method>
      <method-name>findByUsername</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql></ejb-ql>



      <assembly-descriptor>
      <container-transaction>

      <ejb-name>AnesthesiaUser</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>



      <ejb-name>Hospital</ejb-name>
      com.cygnet.medina.Hospital.HospitalHome
      com.cygnet.medina.Hospital.Hospital
      <ejb-class>com.cygnet.medina.Hospital.HospitalEJB</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Hospital</abstract-schema-name>
      <cmp-field>
      <field-name>hospitalid</field-name>
      <column-name>hospitalid</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>hospitalname</field-name>
      <column-name>hospitalname</column-name>
      </cmp-field>
      <primkey-field>hospitalid</primkey-field>

      <assembly-descriptor>
      <container-transaction>

      <ejb-name>Hospital</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>


      </enterprise-beans>
      </ejb-jar>

      Can anyone tell me what the problem is.I am struggling with it for the past 2 days.
      Also FYI I am using Jboss 4.0.2 and MySQL 4.1.13 database

        • 1. Re: Help stuck with JBoss 4.0.2 and MySQL 4.1.13
          Franco Apprentice

          Hi,
          not shure, but maybe the error is in the
          the ejbCreate should return the generated key, not null.

          • 2. Re: Help stuck with JBoss 4.0.2 and MySQL 4.1.13
            Sameer Saptarishi Newbie

            Hello,
            Even if I return the primary key it gives me the same error.
            I have tried it can you tell me whether the ejb-jar.xml and jbosscmp-jdc.xml are correct.


            10:38:02,093 ERROR [LogInterceptor] TransactionRolledbackException in method: public abstract com.cygnet.medina.Hospital.Hospital com.cygnet.medina.Hospital.HospitalHome.create(com.cygnet.medina.Hospital.HospitalData) throws javax.ejb.CreateException,java.rmi.RemoteException, causedBy:
            javax.ejb.EJBException: getGeneratedKeys returned an empty ResultSet
            at org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand.executeInsert(JDBCMySQLCreateCommand.java:87)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:308)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:138)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:572)
            at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:222)
            at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:266)
            at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:766)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
            at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1113)