Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-1893

Finders that use user-type-mappings are broken

    XMLWordPrintable

Details

    Description

      I have a few CMP entity beans which have CMP fields that have user-defined types, particularly Enum type classes (not Java 1.5 enums), for instance in PricingBean I have a Component CMP field that looks like this:

      public abstract PricingComponentType getComponent();

      In jbosscmp-jdbc.xml I have this:

      <user-type-mappings>
      <user-type-mapping>
      <java-type>com.newedgenetworks.phoenix.ejb.entity.PricingComponentType</java-type>
      <mapped-type>java.lang.String</mapped-type>
      <mapper>com.newedgenetworks.phoenix.ejb.entity.PricingComponentType$Mapper</mapper>
      </user-type-mapping>
      <user-type-mappings>

      Works like a champ, love this feature!

      This bean also has a finder which is delcared as follows (class-level XDoclet tags):

      • @ejb.finder
      • signature="Collection findByEntityAndComponent(com.newedgenetworks.phoenix.ejb.entity.BasePK entity, com.newedgenetworks.phoenix.ejb.entity.PricingComponentType component)"
      • query="Overridden by jbosscmp-jdbc.xml"
      • role-name="Pricing View"
        *
      • @jboss.declared-sql
      • signature="Collection findByEntityAndComponent(com.newedgenetworks.phoenix.ejb.entity.BasePK entity, com.newedgenetworks.phoenix.ejb.entity.PricingComponentType component)"
      • where="Object_Type = {0.bean}

        and Object_Key =

        {0.key}

        and Component_Name =

        {1}

        "

      • order="Created_Date desc"

      Now nevermind that BasePK class - that's a DVC and doesn't require a user-mapping.

      When this bean is deployed the following is logged:

      2005-06-09 14:50:44,710 867313 DEBUG org.jboss.ejb.plugins.cmp.jdbc.JDBCDeclaredSQLQuery.Pricing#findByOrderAndComponentAndType (main:jboss.j2ee:jndiName=phoenix/entity/Audit,service=EJB EntityContainer) SQL: SELECT Item_Pricing_Id FROM ITEM_PRICING_DETAILS WHERE Order_Id = ? and Component_Name = ? and Pricing_Type = ?

      2005-06-09 14:50:44,711 867314 WARN [org.jboss.ejb.plugins.cmp.jdbc.JDBCTypeFactory] (main:jboss.j2ee:jndiName=phoenix/entity/Audit,service=EJB EntityContainer) Type not mapped: com.newedgenetworks.phoenix.ejb.entity.PricingComponentType

      Nevermind that the Log4j NDC is incorrect (says jndiName=phoenix/entity/Audit when it really should be jndiName=phoenix/entity/Pricing) that's some odd harmless bug that JBoss has had a long time with incorrect NDC name during EJB deployment.

      That warning message is occuring when PricingBean is being deployed and the CMP system is preparing the SQL query. I've debugged it a little bit and here is the stack trace at that point:

      at org.jboss.ejb.plugins.cmp.jdbc.JDBCTypeFactory.getJDBCType(JDBCTypeFactory.java:390)
      at org.jboss.ejb.plugins.cmp.jdbc.QueryParameter.<init>(QueryParameter.java:210)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQueryCommand.parseParameters(JDBCAbstractQueryCommand.java:368)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCDeclaredSQLQuery.<init>(JDBCDeclaredSQLQuery.java:62)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createDeclaredSQLQuery(JDBCCommandFactory.java:54)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:268)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:490)
      ...

      Looking at JDBCTypeFactory.getJDBCType, it is obviously checking Map of complexTypes (where the DVCs live) and mappedSimpleTypes (normal stuff like java.lang.Long) but the method does not check the third Map this class knows about: userTypeMappings (where PricingComponentType lives).

      The result is that when the finder is executed, the QueryParameter is treated as a BLOB and a SQLException is thrown by the database driver.

      Attachments

        Activity

          People

            olubyans@redhat.com Alexey Loubyansky
            gturner_jira Gerald Turner (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: