Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2352

Retrieving column index for non existing field throws SQLException (ignored) causing slowness in application server

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.1.1
    • None
    • jdbc
    • All OS, I have tried with DB2 but problem may exist for all databases. WebSphere.

    Description

      When we have defined NamedNativeQuery and the query contains let's say 4 columns. Now if we have a resultClass associated to that query which is simply a POJO having let's say five fields, four of which are mapped to the 4 columns of the NamedNativeQuery, but the fifth one is not (after all it is POJO), the JPA tries to retrieve column index for that fifth field, and that throws SQL exception. The JPA code though ignores this exception, returning zero for column index. However, because an exception is throws, the application server in which this code is executing captures it and logs it in its corresponding logs. This causes the population of the result bean slow, and very slow if there are 4-5 or more fields unmapped.

      Here's the code fragment from org.apache.openjpa.jdbc.sql.ResultSetResult.java where this is happening.

      /**

      • Return the 1-based result set index for the given column or id, or a
      • non-positive number if the column is not contained in this result.
        */
        protected int findObject(Object obj, Joins joins)
        throws SQLException {
        try {
        String s1 = obj.toString();
        DBIdentifier sName = DBIdentifier.newColumn(obj.toString());
        return getResultSet().findColumn(_dict.convertSchemaCase(sName));
        } catch (SQLException se) {
        return 0;
        }
        }
        Moreover, this same method is called multiple times for each field, multiplying the problem.

      I would think a better approach would be to use ResultSetMetaData to retrieve all the column names and indexes, cache them and simply return from that cache in the findObject method.

      Is there any reason to keep it like this and not change to use metadata?

      Attachments

        Activity

          People

            Unassigned Unassigned
            rakeshjn Rakesh Jain
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: