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

OpenJPA ignores custom field strategies globally defined in persistence.xml

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.4.1
    • Component/s: None
    • Labels:
      None

      Description

      I use a custom field strategy value handler (a class that extends org.apache.openjpa.jdbc.meta.strats.AbstractValueHandler) for my entities that make use of joda time fields:

      @Entity
      public class MyEntity

      { org.joda.time.LocalDateTime creationDate; }

      When I use the inline strategy annotation (@Strategy("com.xyz.LocalDateValueHandler")), everything works as expected and my LocalDateTime field 'creationDate' gets mapped to an SQL timestamp. However, if I reference my value handler globally in the persistence.xml file, then OpenJPA is not able to find the value handler (i.e., it is never called), which results in a blob column type for 'creationDate'. Here's the corresponding snippet from my persistence.xml:

      <property name="openjpa.jdbc.MappingDefaults" value="FieldStrategies='org.joda.time.LocalDateTime=com.xyz.LocalDateValueHandler"/>

      Note that if I use a mapping from a standard JDK class like java.lang.String to my value handler, then my handler is called as expected. Is this issue somehow related to #OPENJPA-758? Note that I use Derby as my database.

      Any help would be much appreciated.

      1. OPENJPA-2341.patch
        2 kB
        Mark Struberg
      2. OPENJPA-2341-wip-1.patch
        21 kB
        Mark Struberg

        Activity

        Hide
        struberg Mark Struberg added a comment -

        First version, not yet fully working but a start.
        I guess there is a cascade of issues. We tried to write a ValueHandler to convert joda Time values automatically. Reinhard wrote up a sample app for it: https://github.com/rsandtner/openjpa-converter

        The first problem was that any handler was totally ignored if the field was Serializable. The patch fixes this problem and we now at least get the ValueHandler registered in the field. Still some other issues to resolve though...

        Show
        struberg Mark Struberg added a comment - First version, not yet fully working but a start. I guess there is a cascade of issues. We tried to write a ValueHandler to convert joda Time values automatically. Reinhard wrote up a sample app for it: https://github.com/rsandtner/openjpa-converter The first problem was that any handler was totally ignored if the field was Serializable. The patch fixes this problem and we now at least get the ValueHandler registered in the field. Still some other issues to resolve though...
        Hide
        struberg Mark Struberg added a comment -

        Seems the code is fine, just our test sample was not really finished. We just had a ValueHandler for LocalDate but not for the other joda types used in the sample. Removing those columns made the sample green.

        Show
        struberg Mark Struberg added a comment - Seems the code is fine, just our test sample was not really finished. We just had a ValueHandler for LocalDate but not for the other joda types used in the sample. Removing those columns made the sample green.
        Hide
        struberg Mark Struberg added a comment -

        While tinkering a unit test I came across another weird issue. The custom ValueHandlers are totally ignored if the field is not a BASIC column. For some types like joda's LocalDate it works 'by accident' as LocalDate is java.io.Serializable and thus gets detected as 'persistable' by OpenJPA (under FieldStrategy BASIC).

        We need to change this detection and also handle fields which have an explicit ValueHandler or PersistenceStrategy assigned.
        This is not only important for the MetaData factory at runtime but also for all kind of enhancements, esp compile-time and javaagent enhancement!

        Show
        struberg Mark Struberg added a comment - While tinkering a unit test I came across another weird issue. The custom ValueHandlers are totally ignored if the field is not a BASIC column. For some types like joda's LocalDate it works 'by accident' as LocalDate is java.io.Serializable and thus gets detected as 'persistable' by OpenJPA (under FieldStrategy BASIC). We need to change this detection and also handle fields which have an explicit ValueHandler or PersistenceStrategy assigned. This is not only important for the MetaData factory at runtime but also for all kind of enhancements, esp compile-time and javaagent enhancement!
        Hide
        struberg Mark Struberg added a comment -

        The missing field handling is btw also broken even if you explicitly use @Strategy on the field...

        Show
        struberg Mark Struberg added a comment - The missing field handling is btw also broken even if you explicitly use @Strategy on the field...
        Hide
        struberg Mark Struberg added a comment -

        work in progress; these tests fail as the mapped field is a java.security.Principal which is not Serializable.

        Show
        struberg Mark Struberg added a comment - work in progress; these tests fail as the mapped field is a java.security.Principal which is not Serializable.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1688947 from Mark Struberg in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1688947 ]

        OPENJPA-2341 fix ValueHandler pickup via FieldStrategies

        Sadly this atm only works for fields which are Serializable.
        Menas the ValueHandler can just change the presentation right now
        but it doesn't work for mapping non-Serializable classes like
        java.security.Principal.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1688947 from Mark Struberg in branch 'openjpa/trunk' [ https://svn.apache.org/r1688947 ] OPENJPA-2341 fix ValueHandler pickup via FieldStrategies Sadly this atm only works for fields which are Serializable. Menas the ValueHandler can just change the presentation right now but it doesn't work for mapping non-Serializable classes like java.security.Principal.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1689594 from Mark Struberg in branch 'openjpa/trunk'
        [ https://svn.apache.org/r1689594 ]

        OPENJPA-2341 add unit test for Strategy handling

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1689594 from Mark Struberg in branch 'openjpa/trunk' [ https://svn.apache.org/r1689594 ] OPENJPA-2341 add unit test for Strategy handling
        Hide
        struberg Mark Struberg added a comment -

        the handling now works perfectly fine if the field is Serializable. I think we should split out the remaining problems into a separate issue.

        Show
        struberg Mark Struberg added a comment - the handling now works perfectly fine if the field is Serializable. I think we should split out the remaining problems into a separate issue.

          People

          • Assignee:
            struberg Mark Struberg
            Reporter:
            mrueegg Michael Rüegg
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development