OpenJPA
  1. OpenJPA
  2. OPENJPA-2377

Metamodel.managedType returns wrong result for Embeddable

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3.0
    • Component/s: None
    • Labels:
      None

      Description

      I use the following code to dynamically determine if a class is an embeddable:

      Class c = Class.forName(s);
      ManagedType type = metamodel.managedType(c);
      if (type.getPersistenceType() == Type.PersistenceType.EMBEDDABLE)

      { logger.debug("" + c + " is an Embeddable."); // do somthing with the embeddable }

      else if (type.getPersistenceType() == Type.PersistenceType.ENTITY)

      { logger.debug("" + c + " is an Entity."); // do somthing with the entity }

      but when I use this code for an Embeddable, I always get "xxx is an Entity" logged.

      After examining the source code, I found "MetamodelImpl.instantiate" method will always put embeddable to both "embeddables" and "entities" containers, but "MetamodelImpl.managedType" method will first search "entities" and then "embeddables" for a persistence class, thus, "Entity" type will be returned for a ACTUAL Embeddable class.

      Hope this can be fixed.

        Activity

        Azuo Lee created issue -
        Azuo Lee made changes -
        Field Original Value New Value
        Description I use the following code to dynamically determine if a class is an embeddable:

        Class c = Class.forName(s);
        if (c instanceof ManagedType) {
            ManagedType type = metamodel.managedType(c);
            if (type.getPersistenceType() == Type.PersistenceType.EMBEDDABLE) {
                 logger.debug("" + c + " is an Embeddable.");
                 // do somthing with the embeddable
            }
            else if (type.getPersistenceType() == Type.PersistenceType.ENTITY) {
                 logger.debug("" + c + " is an Entity.");
                 // do somthing with the entity
            }
        }

        but when I use this code for an Embeddable, I always get "xxx is an Entity" logged.

        After examining the source code, I found "MetamodelImpl.instantiate" method will always put embeddable to both "embeddables" and "entities" containers, but "MetamodelImpl.managedType" method will first search "entities" and then "embeddables" for a persistence class, thus, "Entity" type will be returned for a ACTUAL Embeddable class.

        Hope this can be fixed.
        I use the following code to dynamically determine if a class is an embeddable:

        Class c = Class.forName(s);
            ManagedType type = metamodel.managedType(c);
            if (type.getPersistenceType() == Type.PersistenceType.EMBEDDABLE) {
                 logger.debug("" + c + " is an Embeddable.");
                 // do somthing with the embeddable
            }
            else if (type.getPersistenceType() == Type.PersistenceType.ENTITY) {
                 logger.debug("" + c + " is an Entity.");
                 // do somthing with the entity
            }
        }

        but when I use this code for an Embeddable, I always get "xxx is an Entity" logged.

        After examining the source code, I found "MetamodelImpl.instantiate" method will always put embeddable to both "embeddables" and "entities" containers, but "MetamodelImpl.managedType" method will first search "entities" and then "embeddables" for a persistence class, thus, "Entity" type will be returned for a ACTUAL Embeddable class.

        Hope this can be fixed.
        Azuo Lee made changes -
        Description I use the following code to dynamically determine if a class is an embeddable:

        Class c = Class.forName(s);
            ManagedType type = metamodel.managedType(c);
            if (type.getPersistenceType() == Type.PersistenceType.EMBEDDABLE) {
                 logger.debug("" + c + " is an Embeddable.");
                 // do somthing with the embeddable
            }
            else if (type.getPersistenceType() == Type.PersistenceType.ENTITY) {
                 logger.debug("" + c + " is an Entity.");
                 // do somthing with the entity
            }
        }

        but when I use this code for an Embeddable, I always get "xxx is an Entity" logged.

        After examining the source code, I found "MetamodelImpl.instantiate" method will always put embeddable to both "embeddables" and "entities" containers, but "MetamodelImpl.managedType" method will first search "entities" and then "embeddables" for a persistence class, thus, "Entity" type will be returned for a ACTUAL Embeddable class.

        Hope this can be fixed.
        I use the following code to dynamically determine if a class is an embeddable:

        Class c = Class.forName(s);
        ManagedType type = metamodel.managedType(c);
        if (type.getPersistenceType() == Type.PersistenceType.EMBEDDABLE) {
             logger.debug("" + c + " is an Embeddable.");
             // do somthing with the embeddable
        }
        else if (type.getPersistenceType() == Type.PersistenceType.ENTITY) {
             logger.debug("" + c + " is an Entity.");
             // do somthing with the entity
        }

        but when I use this code for an Embeddable, I always get "xxx is an Entity" logged.

        After examining the source code, I found "MetamodelImpl.instantiate" method will always put embeddable to both "embeddables" and "entities" containers, but "MetamodelImpl.managedType" method will first search "entities" and then "embeddables" for a persistence class, thus, "Entity" type will be returned for a ACTUAL Embeddable class.

        Hope this can be fixed.
        Albert Lee made changes -
        Assignee Albert Lee [ allee8285 ]
        Albert Lee made changes -
        Attachment OPENJPA-2377.trunk.patch [ 12581753 ]
        Albert Lee made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3.0 [ 12319463 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Albert Lee
            Reporter:
            Azuo Lee
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development