OpenJPA
  1. OpenJPA
  2. OPENJPA-1577

Using @Strategy in Queries not working properly

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-beta2
    • Fix Version/s: 2.0.0-beta3
    • Component/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 9.10, Maven 2.2.1, Spring 3.0.1
    • Patch Info:
      Patch Available

      Description

      I try to use a field that is annotated with @Strategy in a Query.

      I expected that everytime the query is executed the toDataStoreValue method of the ValueHandler is called to prepare the correct values for the SQL query.
      This is only happens once. The next time the Query is executed the ValueHandler is not called.

      Here is the interesting part of the logging

      1st call:
      [DEBUG,Query,main] Executing query: [select s from SimpleEntity s where s.base = :base and s.name = :name] with parameters:

      {name=james, base=1}

      toDataStoreValue: 1
      [DEBUG,SQL,main] <t 805562662, conn 2071272094> executing prepstmnt 1531692262 SELECT t0.id, t0.version, t0.base, t0.street, t0.my_name FROM some_objects t0 WHERE (t0.base = ? AND t0.my_name = ?) [params=(String) base1, (String) james]

      2nd call:
      [DEBUG,Query,main] Executing query: [select s from SimpleEntity s where s.base = :base and s.name = :name] with parameters:

      {0=2, 1=henry}

      [DEBUG,SQL,main] <t 805562662, conn 2071272094> executing prepstmnt 106030716 SELECT t0.id, t0.version, t0.base, t0.street, t0.my_name FROM some_objects t0 WHERE (t0.base = ? AND t0.my_name = ?) [params=(String) 2, (String) henry]

      You can see that the parameter list has changed after the first call. Some kind of transformation (caching?) prevents calling the ValueHandler again.
      This is only a vague presumption.

      1. OPENJPA-1577.patch
        8 kB
        Fay Wang
      2. openjpa1577.tar
        7 kB
        Oliver Ringel
      3. OPENJPA-1577-1.patch
        8 kB
        Fay Wang

        Activity

        Hide
        Fay Wang added a comment -

        Yes, it is possible to not to disable query cache. We will explore this possibility.

        Show
        Fay Wang added a comment - Yes, it is possible to not to disable query cache. We will explore this possibility.
        Hide
        Oliver Ringel added a comment -

        The patch fixed the issue. My queries are working now. Again, thanks for the help.

        One questions. Is disabling the query cache the final solution?
        It would be nice if that would not be necessary and I guess that should be possible.

        Show
        Oliver Ringel added a comment - The patch fixed the issue. My queries are working now. Again, thanks for the help. One questions. Is disabling the query cache the final solution? It would be nice if that would not be necessary and I guess that should be possible.
        Hide
        Fay Wang added a comment -

        Hi Oliver, can you try to see if it works for your query?

        Show
        Fay Wang added a comment - Hi Oliver, can you try to see if it works for your query?
        Hide
        Fay Wang added a comment -

        This patch is based on the latest trunk level code.

        Show
        Fay Wang added a comment - This patch is based on the latest trunk level code.
        Hide
        Fay Wang added a comment -

        Yes, this problem is due to the query cache. The patch disables the cache for queries that make use of user-defined strategy.

        Show
        Fay Wang added a comment - Yes, this problem is due to the query cache. The patch disables the cache for queries that make use of user-defined strategy.
        Hide
        Fay Wang added a comment -

        I can reproduce this problem. Will take a look.

        Show
        Fay Wang added a comment - I can reproduce this problem. Will take a look.
        Hide
        Oliver Ringel added a comment -

        Here is the test case.

        Show
        Oliver Ringel added a comment - Here is the test case.

          People

          • Assignee:
            Fay Wang
            Reporter:
            Oliver Ringel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development