Weblogic generating bad finder code

Discussions

EJB programming & troubleshooting: Weblogic generating bad finder code

  1. Weblogic generating bad finder code (1 messages)

    I am using Weblogic 6.1 sp2. I defined a finder on a cmp bean that takes a parameter. The code that weblogic generates for the finder does not set the parameters in the prepared statement.

    Is there something that I am doing wrong? Is this a weblogic bug. I found no mention of it on their site.

    Generated Code:
    public java.util.Collection ejbFindByPcPayclass(java.lang.String param0) throws javax.ejb.FinderException
        {
        if(__WL_verbose) {
          Debug.say("called findByPcPayclass");
        }

        java.sql.Connection __WL_con = null;
        java.sql.PreparedStatement __WL_stmt = null;
        java.sql.ResultSet __WL_rs = null;

            __WL_pm.flushModifiedBeans();


        try {
          __WL_con = __WL_pm.getConnection();
        } catch (java.lang.Exception e) {
          __WL_pm.releaseResources(__WL_con, __WL_stmt, __WL_rs);
          throw new javax.ejb.FinderException("Couldn't get connection: " + EOL +
            e.toString() + EOL +
            RDBMSUtils.throwable2StackTrace(e));
        }

        try {
          java.lang.String __WL_query = "SELECT WL0.DEPOSIT_UID, WL0.GLA_ID, WL0.MARKET_CODE FROM payment_type WL2, payment_type WL1, payments WL0 WHERE (WL2.PC_PAYCLASS = '?1') AND WL0.PT_UID = WL2.PT_UID " + __WL_pm.selectForUpdate();
          if(__WL_verbose) {
            Debug.say("Finder produced statement string " + __WL_query);
          }

          __WL_stmt = __WL_con.prepareStatement(__WL_query);

          
          // preparedStatementParamIndex reset.
          


          __WL_rs = __WL_stmt.executeQuery();
        } catch (java.lang.Exception e) {
          __WL_pm.releaseResources(__WL_con, __WL_stmt, __WL_rs);
          throw new javax.ejb.FinderException(
            "Exception in findByPcPayclass while preparing or executing " +
            "statement: '" + __WL_stmt + "'" + EOL +
            e.toString() + EOL +
            RDBMSUtils.throwable2StackTrace(e));
        }

    ...
    ------------------------------------------------

    Deployment descriptors excerts:

    ejb-jar.xml:
                <query>
                    <query-method>
                        <method-name>findByPcPayclass</method-name>
                        <method-params>
                              <method-param>java.lang.String</method-param>
                        </method-params>
                    </query-method>
                    <ejb-ql>SELECT DISTINCT OBJECT(p) FROM Payments p, PaymentType t WHERE p.paymentType.pcPayClass = '?1'</ejb-ql>
                </query>

    weblogic-cmp-rdbms-jar.xml:
             <weblogic-query>
                <query-method>
                    <method-name>findByPcPayclass</method-name>
                    <method-params>
                         <method-param>java.lang.String</method-param>
                    </method-params>
                </query-method>
                <include-updates>true</include-updates>
            </weblogic-query>



  2. Hi Eugene,

    I think you've got some quotes too many in your query:

    WHERE p.paymentType.pcPayClass = '?1'
    should be:
    WHERE p.paymentType.pcPayClass = ?1

    If you put the quotes in then WL treats ?1 as a literal string, not as a variable... just like it should.

    Cheers,

    Daniel.