OpenJPA
  1. OpenJPA
  2. OPENJPA-1360

ReverseMappingTool omits nullable, length, etc. when ClassMapping.setEmbedded(true) is called

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.3.0, 2.0.0-beta3
    • Component/s: tooling
    • Labels:
      None

      Description

      In my ReverseCustomizer, I call classMapping.setEmbedded(true). This is because for a variety of reasons I need the code that is generated by the ReverseMappingTool to be @MappedSuperclasses, not @Entities.

      Indeed when I do this, the resulting class is a @MappedSuperclass (great!) BUT all of the length and nullable and other @Column attributes are missing. In other words, all simple fields receive only a @Basic annotation, with no attributes, and nothing else. In addition, the class declaration receives a @Table annotation with no attributes. (I'm using the command line flag that instructs the ReverseMappingTool to generate annotations.)

      Ideally I'd like the generated source code to look identical to the source code that would be generated for a ClassMapping where setEmbedded(true) was never called, except of course that I want the @Entity annotation to be replaced with @MappedSuperclass.

      Obviously if there is a better way from within a ReverseCustomizer for me to accomplish my (very odd) goals (mandated by a strange development process and a 30-year-old database), I am all ears.

        Issue Links

          Activity

          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open In Progress In Progress
          136d 2h 27m 1 Donald Woods 08/Mar/10 18:20
          In Progress In Progress Resolved Resolved
          3h 28m 1 Donald Woods 08/Mar/10 21:48
          Resolved Resolved Closed Closed
          21d 1h 29m 1 Donald Woods 30/Mar/10 00:17
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Donald Woods made changes -
          Fix Version/s 2.0.0-beta3 [ 12314857 ]
          Fix Version/s 2.0.0 [ 12314019 ]
          Donald Woods made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Donald Woods made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Donald Woods made changes -
          Attachment OPENJPA-1360-trunk.patch [ 12438211 ]
          Hide
          Donald Woods added a comment -

          Proposed patch based on 1.3.x changes. Need to run a full set of junits and TCK before committing to trunk.

          Show
          Donald Woods added a comment - Proposed patch based on 1.3.x changes. Need to run a full set of junits and TCK before committing to trunk.
          Donald Woods made changes -
          Assignee Donald Woods [ drwoods ]
          Fix Version/s 1.3.0 [ 12313326 ]
          Fix Version/s 2.0.0 [ 12314019 ]
          Affects Version/s 1.2.2 [ 12313681 ]
          Affects Version/s 1.3.0 [ 12313326 ]
          Affects Version/s 2.0.0 [ 12314019 ]
          Laird Nelson made changes -
          Link This issue relates to OPENJPA-1492 [ OPENJPA-1492 ]
          Hide
          Laird Nelson added a comment -

          This bug is still present in openjpa 1.2.2, even with the new ClassMapping.isAbstract() method.

          Show
          Laird Nelson added a comment - This bug is still present in openjpa 1.2.2, even with the new ClassMapping.isAbstract() method.
          Hide
          Laird Nelson added a comment - - edited

          Talking to myself it seems....

          I've successfully implemented the workaround as described in my prior comment.

          The isMappingMode(ClassMetaData) method of my serializer now looks like this:

          @Override
          public boolean isMappingMode(final ClassMetaData meta)

          { return this.isMappingMode() && (meta.getSourceMode() & MetaDataModes.MODE_MAPPING) != 0 && (meta.getEmbeddingMetaData() == null || this.isMappingMode(meta.getEmbeddingMetaData())); }
          Show
          Laird Nelson added a comment - - edited Talking to myself it seems.... I've successfully implemented the workaround as described in my prior comment. The isMappingMode(ClassMetaData) method of my serializer now looks like this: @Override public boolean isMappingMode(final ClassMetaData meta) { return this.isMappingMode() && (meta.getSourceMode() & MetaDataModes.MODE_MAPPING) != 0 && (meta.getEmbeddingMetaData() == null || this.isMappingMode(meta.getEmbeddingMetaData())); }
          Hide
          Laird Nelson added a comment -

          It looks like, at least for the annotations path, AnnotationPersistenceMetaDataSerializer is the culprit. At line 202 or thereabouts, in the isMappingMode(ClassMetaData meta) method, it includes a check to see if the supplied meta isEmbeddedOnly(). If it is, then there is nothing else you can do from the standpoint of your ReverseCustomizer: that metdata is deemed to NOT be in mapping mode. That of course means that when the Java code is written out, all fields are output with only a @Basic annotation and nothing else.

          The (rather cumbersome) workaround is to subclass both this serializer and PersistenceMappingFactory and supply a PersistenceMappingFactory implementation that returns new instances of an AnnotationPersistenceMetaDataSerializer that is capable of omitting this isEmbeddedOnly() check from its own implementation of the isMappingMode(ClassMetaData meta) method.

          Show
          Laird Nelson added a comment - It looks like, at least for the annotations path, AnnotationPersistenceMetaDataSerializer is the culprit. At line 202 or thereabouts, in the isMappingMode(ClassMetaData meta) method, it includes a check to see if the supplied meta isEmbeddedOnly(). If it is, then there is nothing else you can do from the standpoint of your ReverseCustomizer: that metdata is deemed to NOT be in mapping mode. That of course means that when the Java code is written out, all fields are output with only a @Basic annotation and nothing else. The (rather cumbersome) workaround is to subclass both this serializer and PersistenceMappingFactory and supply a PersistenceMappingFactory implementation that returns new instances of an AnnotationPersistenceMetaDataSerializer that is capable of omitting this isEmbeddedOnly() check from its own implementation of the isMappingMode(ClassMetaData meta) method.
          Laird Nelson made changes -
          Field Original Value New Value
          Comment [ I think there may be something wrong with MetaDataRepository.java line 727 and 728. The comment reads:
                      // embedded-only metadata doesn't have mapping, so always loaded

          Immediately beneath that is a block that then proceeds to do some sophisticated loading of metadata in the event a ClassMetaData is NOT set to be embedded only.

          As it turns out, a MappedSuperclass is allowed, right?, to "have mapping". Specifically, a MappedSuperclass may certainly have @Column annotations.

          So I think that whatever magic machinery (and I've gone goggle eyed trying to figure out exactly what that machinery is) below this point that is responsible for loading up the information necessary to determine that a @Column annotation should be output is being short-circuited. ]
          Laird Nelson created issue -

            People

            • Assignee:
              Donald Woods
              Reporter:
              Laird Nelson
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development