Uploaded image for project: 'Hibernate ORM'
  1. HHH-5161

JPA 2.0 criteria queries do not use parameters for numeric fields

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Rejected
    • Affects Version/s: 3.5.0-Final
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Hibernate 3.5.0 with Oracle DB.
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      Using the new JPA 2.0 criteria API to create a query whose where clause consists of one or more predicates, where one of those predicates compares a numeric (int or long) field in an entity to a certain value, the generated query uses the compared value literally in the query where it should have used a parameter.

      The attached test case illustrates the problem. It's a minimal Maven2 project which contains one domain class and one DAO.

      The domain class maps to the REGION entity from the Oracle HR schema which ships with any Oracle XE installation. I still included the script needed to create the table incase the schema is not available on the test environment.

      The DAO has one method which creates a query that selects a region by id and then extracts the set of parameters from the generated TypedQuery. The method then returns the size of the set to the test method which fails if the size is not greater than zero.

      The DAO method also executes the query and since Hibernate is configured to show the generated SQL, the following query is shown in standard output:

      select
      region0_.REGION_ID as REGION1_0_,
      region0_.REGION_NAME as REGION2_0_
      from
      REGIONS region0_
      where
      region0_.REGION_ID=1

      Where the correct query should have been:

      select
      region0_.REGION_ID as REGION1_0_,
      region0_.REGION_NAME as REGION2_0_
      from
      REGIONS region0_
      where
      region0_.REGION_ID=?

      IMO, this is a major issue as it can have a severe impact on on Oracle DB performance as it will have to hard parse the query every time it's used with a different value.

      I've provided instructions on the minimal changes required to setup the Maven project in order to run the test case in "readme.txt".

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: