Uploaded image for project: 'The AndroMDA project'
  1. ANDROMDA-823

Hibernate <joined-subclass> mapping generates superfluous *.hbm.xml files

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0-RC1
    • Component/s: None
    • Labels:
      None

      Description

      Let's assume the user has three entities A, B, C where B and C specialize A.

      When a user sets the inheritance mapping strategy to "subclass" (which really means <joined-subclass>) then the Spring cartridge correctly generates A.hbm.xml with

      <class name="AImpl" table="A">
      <joined-subclass name="BImpl" table="B">
      ...
      </joined-subclass>
      <joined-subclass name="CImpl" table="C">
      ...
      </joined-subclass>
      </class>

      BUT: it also generates additional, superfluous files B.hbm.xml and C.hbm.xml! Hibernate schema mapper complains about "duplicate imports" for BImpl and CImpl.

      Looking at the code for SpringEntityLogicImpl, there is a complex method that tries to guess whether a .hbm.xml file needs to be written or not:

      <code>
      protected boolean handleIsRootInheritanceEntity()
      {
      boolean result = false;
      GeneralizableElementFacade superElement = this.getGeneralization();
      if (superElement == null)

      { String inheritance = this.getInheritance(this); // We are a root if we are the base class and not interface // inheritance result = (inheritance == null) || !inheritance.equals(INHERITANCE_STRATEGY_INTERFACE); }

      else
      {
      // We are a subclass
      GeneralizableElementFacade root = getRootInheritanceEntity();
      String inheritance = getInheritance(root);
      // Are we the subclass element
      result = root.getFullyQualifiedName().equals(
      getFullyQualifiedName());
      if (!result && inheritance != null
      && inheritance.equals(INHERITANCE_STRATEGY_SUBCLASS))

      { // If not check if we are a subclass result = superElement.getFullyQualifiedName().equals( root.getFullyQualifiedName()); }

      }
      return result;
      }
      </code>

      The bug seems to be in this method (I think it is somewhere in the "else" clause).

      HOWEVER: I suggest to throw away this method and ALWAYS write one .hbm.xml file per class, using a different syntax. This syntax allows to use <subclass> and <joined-subclass> mapping elements in a separate mapping file (as a top level element, instead of <class>). You then have to declare the class that is extended (for example write a new file B.hbm.xml with:

      <subclass name="B" extends="A">
      ...
      </subclass>

      This would be MUCH simpler, you can also throw away the getRootInheritanceEntity() method altogether. The price for this is: at runtime, you have to load A.hbm.xml before B.hbm.xml and C.hbm.xml.

        Attachments

          Activity

            People

            • Assignee:
              overheat overheat
              Reporter:
              mattes3 Matthias Bohlen
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: