1 Reply Latest reply on Oct 8, 2001 3:24 PM by espenk

    Strange behaviour

    espenk

      Hello,

      I'm using JBoss 2.2.2 and something strange is happening:

      [JAWS] Exists command executing: SELECT COUNT(*) FROM Person WHERE personid=?
      [JAWS] Set parameter: idx=1, jdbcType=INTEGER, value=7
      [JAWS] Create command executing: INSERT INTO Person (personname,personid) VALUES (?,?)
      [JAWS] Set parameter: idx=1, jdbcType=VARCHAR, value=Isabel
      [JAWS] Set parameter: idx=2, jdbcType=INTEGER, value=7
      [JAWS] Rows affected = 1
      [Person] PostCreate: class as.koren.calendar.IntegerKey
      [JAWS] Store command executing: UPDATE Counter SET countervalue=? WHERE countername=?
      [JAWS] Set parameter: idx=1, jdbcType=INTEGER, value=7
      [JAWS] Set parameter: idx=2, jdbcType=VARCHAR, value=Person
      [JAWS] Rows affected = 1
      [DataSource] Pool DataSource [0/1/Unlimited] returned object org.opentools.minerva.jdbc.xa.wrapper.XAConnectionImpl@64f7c2 to the pool.
      [Person] Store: class as.koren.calendar.IntegerKey
      [Person] Activate: class $Proxy96
      [Person] Activated bean Person with id = calendar/Person:7

      According to this log, the primary key class changes from being IntegerKey (as it should be) to the proxy of the bean!!!! The $Proxy96 could be casted to Person without ClassCastException !!!

      It is CMP, and as you can see in ejbPostCreate the class is correct (I print out entityContext.getPrimaryKey().getClass() ...). In ejbStore everything seems OK still, but then in ejbActivate the class has changed to $Proxy96 ... WHY?????

      Some code:
      Person.java:
      public interface Person extends EJBObject {
      public int getId() throws RemoteException;
      public String getName() throws RemoteException;
      }

      PersonHome.java:
      public interface PersonHome extends EJBHome {
      public static final String JNDI_NAME = "calendar/Person";
      public Person create(String p_name) throws RemoteException, CreateException;
      public Person findByPrimaryKey(IntegerKey primaryKey) throws RemoteException, FinderException;
      }

      PersonBean.java:
      public class PersonBean implements EntityBean {
      private EntityContext entityContext;
      private IdGeneratorHome m_idGeneratorHome;
      public int m_id;
      public String m_name;

      public IntegerKey ejbCreate(String p_name) throws CreateException {
      try {
      m_id = (int)m_idGeneratorHome.create().getNewId("Person");
      } catch (RemoteException e) {
      throw new CreateException("Could not create ID for Event. " + e.getMessage());
      }
      m_name = p_name;
      return null;
      }

      public void ejbPostCreate(String p_name) throws CreateException {
      System.out.println("PostCreate: " + entityContext.getPrimaryKey().getClass());
      }

      public void ejbRemove() throws RemoveException {}
      public void ejbActivate() {
      System.out.println("Activate: " + entityContext.getPrimaryKey().getClass());
      }

      public void ejbPassivate() {
      System.out.println("Passivate: " + entityContext.getPrimaryKey());
      }
      public void ejbLoad() {
      System.out.println("Load: " + entityContext.getPrimaryKey());
      }
      public void ejbStore() {
      System.out.println("Store: " + entityContext.getPrimaryKey().getClass());
      }

      public void setEntityContext(EntityContext entityContext) {
      this.entityContext = entityContext;
      try {
      m_idGeneratorHome = (IdGeneratorHome)new InitialContext().lookup(IdGeneratorHome.REF_NAME);
      } catch (NamingException e) {
      throw new EJBException(e);
      }
      }

      public void unsetEntityContext() {
      entityContext = null;
      }

      public int getId() {
      return m_id;
      }

      public String getName() {
      return m_name;
      }
      }

      IntegerKey.java:
      public class IntegerKey implements java.io.Serializable {
      public int m_id;
      public IntegerKey() {
      }
      public IntegerKey(int p_key) {
      m_id = p_key;
      }
      public boolean equals(Object obj) {
      if (getClass().equals(obj.getClass())) {
      IntegerKey that = (IntegerKey) obj;
      return m_id == that.m_id;
      }
      return false;
      }
      public int hashCode() {
      return m_id;
      }
      public String toString() {
      return String.valueOf(m_id);
      }
      }

      ejb-jar.xml (only the entity-tag):

      <ejb-name>Person</ejb-name>
      as.koren.calendar.PersonHome
      as.koren.calendar.Person
      <ejb-class>as.koren.calendar.PersonBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>as.koren.calendar.IntegerKey</prim-key-class>
      False
      <cmp-field>
      <field-name>m_id</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>m_name</field-name>
      </cmp-field>
      <ejb-ref>
      <ejb-ref-name>ejb/IdGenerator</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      as.koren.util.idgen.IdGeneratorHome
      as.koren.util.idgen.IdGenerator
      <ejb-link />
      </ejb-ref>
      <resource-ref>
      <res-ref-name>jdbc/CalendarPool</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>


      jboss.xml:

      <ejb-name>Person</ejb-name>
      <jndi-name>calendar/Person</jndi-name>
      <configuration-name></configuration-name>
      <ejb-ref>
      <ejb-ref-name>ejb/IdGenerator</ejb-ref-name>
      <jndi-name>idcounter/IdGenerator</jndi-name>
      </ejb-ref>
      <resource-ref>
      <res-ref-name>jdbc/CalendarPool</res-ref-name>
      <resource-name>jdbc/DataSource</resource-name>
      </resource-ref>


      jaws.xml:

      <ejb-name>Person</ejb-name>
      <table-name>Person</table-name>
      <create-table>true</create-table>
      <remove-table>true</remove-table>
      <tuned-updates>true</tuned-updates>
      <read-only>false</read-only>
      <time-out>300</time-out>
      <pk-constraint>false</pk-constraint>
      <cmp-field>
      <field-name>m_id</field-name>
      <column-name>personid</column-name>
      <sql-type>INTEGER</sql-type>
      <jdbc-type>INTEGER</jdbc-type>
      </cmp-field>
      <cmp-field>
      <field-name>m_name</field-name>
      <column-name>personname</column-name>
      <sql-type>VARCHAR(256)</sql-type>
      <jdbc-type>VARCHAR</jdbc-type>
      </cmp-field>


      I'm using OPTA 2000 as JDBC-driver and hence MS SQLSERVER ...

      Sp1

        • 1. Re: Strange behaviour
          espenk

          I have found some more too. I ran JBoss inside JBuilder to debug a bit. I cannot understand what is happening between the ejbStore and the ejbActivate.

          I put a break point in "runWithTransactions" in "TxInterceptorCMT", and the object "mi" there, which represents the method that is going to be called, changes its attribute "id" between the call to store and the call to activate.

          The most strange thing is that the "wrong" id in fact is the beans own proxy ...

          Sp1