Uploaded image for project: 'Corda'
  1. CORDA-1267

Corda's JPA classes should not be final or have final methods

    Details

    • Type: Bug
    • Status: Done (View workflow)
    • Priority: Medium
    • Resolution: Done
    • Affects versions: None
    • Fix versions: Corda 3.1
    • Components: None
    • Labels:
      None

      Description

      The JEE7 specification stipulates the following for @Entity and @Embeddable objects (and presumably @MappedSuperclass ones too):

      1. The class must be annotated with the javax.persistence.Entity annotation.
      2. The class must have a public or protected, no-argument constructor. The class may have other constructors.
      3. The class must not be declared final. No methods or persistent instance variables must be declared final.
      4. If an entity instance is passed by value as a detached object, such as through a session bean's remote business interface, the class must implement the Serializable interface.

      However, the net.corda.core.schemas.PersistentStateRef class and both entities in net.corda.finance.schemas are declared as final, as are almost all of their methods. Similarly, while net.corda.core.schemas.PersistentState, net.corda.core.schemas.CommonSchemaV1$LinearState and net.corda.core.schemas.CommonSchemaV1$FungibleState are not final, most of their methods are. This means that JPA cannot create proxies for any of these classes.

      The solution is to apply the kotlin-allopen plugin to the core and finance modules.

      apply plugin: 'kotlin-allopen'
      
      allOpen {
          annotations(
              "javax.persistence.Entity",
              "javax.persistence.Embeddable",
              "javax.persistence.MappedSuperclass"
          )
      }
      

      To be fair, we should probably also ask whether these classes should implement java.io.Serializable as well.

        Attachments

          Activity

            People

            • Assignee:
              removed86 Former user (Inactive)
              Reporter:
              chris.rankin Chris Rankin
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: