2 Replies Latest reply on Feb 26, 2002 10:45 PM by Jimmy

    EJBselect problems with JBoss 3

    Jimmy Newbie

      Hi,

      I'm using the latest CVS version of JBoss and mysql 3.23.47. I'm trying out the Judges EJB examples in the Wrox book on JBoss (they worked on J2EE RI) and I ran into a problem. This example has 2 Entity beans with a one to many relationship (1 judge to many cases). The ejbselect method that fails is supposed to fetch a case object(local interface) from a given primary key. The method is called ejbSelectCase.

      In JudgeBean.java, I have:

      public abstract CaseLocal ejbSelectCase(Long docketNumber)
      throws FinderException;

      My relevant ejb-jar.xml section is:

      <ejb-jar>
      <display-name>judge_case</display-name>
      <enterprise-beans>

      <display-name>JudgeEJB</display-name>
      <ejb-name>JudgeEJB</ejb-name>
      examples.judge_case.JudgeHome
      examples.judge_case.Judge
      <ejb-class>examples.judge_case.JudgeBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      True
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>JudgeBean</abstract-schema-name>
      <cmp-field><field-name>judgeName</field-name></cmp-field>
      <cmp-field><field-name>judgeId</field-name></cmp-field>
      <primkey-field>judgeId</primkey-field>
      <ejb-local-ref>
      <ejb-ref-name>ejb/CaseLocal</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>examples.judge_case.CaseLocalHome</local-home>
      examples.judge_case.CaseLocal
      <ejb-link>CaseEJB</ejb-link>
      </ejb-local-ref>

      <query-method>
      <method-name>ejbSelectCase</method-name>
      <method-params>
      <method-param>java.lang.Long</method-param>
      </method-params>
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql>SELECT OBJECT(c) FROM CaseBean c WHERE c.docketNumber = ?1</ejb-ql>


      <query-method>
      <method-name>ejbSelectCases</method-name>
      <method-params>
      <method-param>int</method-param>
      </method-params>
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql>
      SELECT OBJECT(c) FROM JudgeBean jb, IN (jb.AssignedCases) c WHERE jb.judgeId = ?1
      </ejb-ql>


      <query-method>
      <method-name>ejbSelectJudge</method-name>
      <method-params>
      <method-param>int</method-param>
      </method-params>
      </query-method>
      <result-type-mapping>Remote</result-type-mapping>
      <ejb-ql>
      SELECT OBJECT(jb) FROM JudgeBean jb WHERE jb.judgeId = ?1
      </ejb-ql>




      <display-name>CaseEJB</display-name>
      <ejb-name>CaseEJB</ejb-name>
      <local-home>examples.judge_case.CaseLocalHome</local-home>
      examples.judge_case.CaseLocal
      <ejb-class>examples.judge_case.CaseBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      True
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>CaseBean</abstract-schema-name>
      <cmp-field>
      <field-name>caseName</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>docketNumber</field-name>
      </cmp-field>
      <primkey-field>docketNumber</primkey-field>
      <security-identity>
      <use-caller-identity></use-caller-identity>
      </security-identity>

      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name></ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>JudgeEJB</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>JudgeEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>AssignedCases</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>CaseEJB</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      <ejb-name>CaseEJB</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      I get the following error in my log file when I try to execute the above ejbselect method:


      2002-02-26 01:09:25,320 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.CaseEJB] Store command NOT executed. Entity is not dirty: pk=1000
      2002-02-26 01:09:25,320 DEBUG [org.jboss.tm.TxCapsule] registerSynchronization(): Entered, tx=XidImpl [FormatId=257, GlobalId=jkan//3, BranchQual=] status=STATUS_ACTIVE
      2002-02-26 01:09:25,320 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.JudgeEJB] Store command NOT executed. Entity is not dirty: pk=1

      *********************************************************
      2002-02-26 01:09:25,320 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.JudgeEJB.ejbSelectCase] Executing SQL: SELECT t1_c.docketNumber FROM CaseEJB t1_c WHERE t1_c.docketNumber = ?
      2002-02-26 01:09:25,320 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.JudgeEJB.ejbSelectCase] Set parameter: index=1, jdbcType=BIGINT, value=1000
      **********************************************************

      2002-02-26 01:09:25,320 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.CaseEJB.docketNumber] Get result: index=1, javaType=java.lang.Long, Simple, value=1000
      2002-02-26 01:09:25,330 DEBUG [org.jboss.tm.TxCapsule] registerSynchronization(): Entered, tx=XidImpl [FormatId=257, GlobalId=jkan//3, BranchQual=] status=STATUS_ACTIVE
      2002-02-26 01:09:25,330 DEBUG [org.jboss.tm.TxCapsule] setRollbackOnly(): Entered, tx=XidImpl [FormatId=257, GlobalId=jkan//3, BranchQual=] status=STATUS_ACTIVE
      2002-02-26 01:09:25,330 DEBUG [org.jboss.tm.TxCapsule] rollback(): Entered, tx=XidImpl [FormatId=257, GlobalId=jkan//3, BranchQual=] status=STATUS_MARKED_ROLLBACK
      2002-02-26 01:09:25,330 DEBUG [org.jboss.tm.TxManager] suspended tx: TransactionImpl:XidImpl [FormatId=257, GlobalId=jkan//3, BranchQual=]
      2002-02-26 01:09:25,340 ERROR [org.jboss.ejb.EntityContainer] invoke returned an exception
      java.rmi.ServerException: null
      Embedded Exception
      $Proxy15; nested exception is:
      javax.ejb.EJBException: null
      Embedded Exception
      $Proxy15
      javax.ejb.EJBException: null
      Embedded Exception
      $Proxy15
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1023)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadInterceptor.invoke(JDBCReadAheadInterceptor.java:92)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:184)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:295)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:189)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:108)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:158)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:64)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:435)
      at org.jboss.ejb.Container.invoke(Container.java:609)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:113)
      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:149)
      at org.jboss.proxy.ejb.GenericProxy.invoke(GenericProxy.java:182)
      at org.jboss.proxy.ejb.EntityProxy.invoke(EntityProxy.java:134)
      at $Proxy13.transferCase(Unknown Source)
      at examples.judge_case.judgeservlet.doGet(judgeservlet.java:34)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:327)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:546)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1269)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1223)
      at org.mortbay.http.HttpServer.service(HttpServer.java:725)
      at org.mortbay.http.HttpConnection.service(HttpConnection.java:748)
      at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:921)
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:763)
      at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:138)
      at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287)
      at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:715)
      at java.lang.Thread.run(Unknown Source)
      java.lang.ClassCastException: $Proxy15
      at examples.judge_case.JudgeBean$Proxy.ejbSelectCase(Unknown Source)
      at examples.judge_case.JudgeBean.transferCase(JudgeBean.java:81)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1012)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadInterceptor.invoke(JDBCReadAheadInterceptor.java:92)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:184)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:295)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:189)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:108)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:158)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:64)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:435)
      at org.jboss.ejb.Container.invoke(Container.java:609)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:113)
      at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:149)
      at org.jboss.proxy.ejb.GenericProxy.invoke(GenericProxy.java:182)
      at org.jboss.proxy.ejb.EntityProxy.invoke(EntityProxy.java:134)
      at $Proxy13.transferCase(Unknown Source)
      at examples.judge_case.judgeservlet.doGet(judgeservlet.java:34)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:327)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:546)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1269)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1223)
      at org.mortbay.http.HttpServer.service(HttpServer.java:725)
      at org.mortbay.http.HttpConnection.service(HttpConnection.java:748)
      at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:921)
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:763)
      at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:138)
      at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287)
      at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:715)
      at java.lang.Thread.run(Unknown Source)
      2002-02-26 01:09:25,400 ERROR [Default] java.rmi.ServerException: null
      Embedded Exception
      $Proxy15; nested exception is:
      javax.ejb.EJBException: null
      Embedded Exception
      $Proxy15
      2002-02-26 01:09:25,410 ERROR [Default] javax.ejb.EJBException: null
      Embedded Exception
      $Proxy15
      2002-02-26 01:09:25,410 ERROR [Default] <<no stack trace available>>
      2002-02-26 01:09:25,410 ERROR [Default] java.lang.ClassCastException: $Proxy15
      2002-02-26 01:09:25,410 ERROR [Default] <<no stack trace available>>


      I'm sure my database is correctly set up, can anyone help?
      Could it be something to do with the primary key being java.lang.Long instead of long? I had to use java.lang.Long because JBoss wouldn't let me use long.

      Thanks,

      Jim

        • 1. Re: EJBselect problems with JBoss 3
          Mika Kuusela Newbie

          Hi,

          I used to have this problem also with the earlier versions of JBoss 3.0. In current release (jboss-3.0.0beta2) the Judge-Case example works correctly. I still have problems when trying to use jbosscmp-jdbc.xml -file to customize the default behaviour of creating tables and stuff, but without it, it works just fine.

          So my suggestion is that you download the latest version from the CVS, build it and get going.

          Regards,
          Mika

          • 2. Re: EJBselect problems with JBoss 3
            Jimmy Newbie

            Thanks for your reply. Actually I'm already using the CVS from Feb 25th. Maybe I should try the packaged beta instead.

            Did you have to change your primary key inside your bean class so that they are real objects instead of Java primitives? I had to do that.

            Thanks

            Jimmy