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

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


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


      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 name="CImpl" table="C">

      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:

      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); }

      // We are a subclass
      GeneralizableElementFacade root = getRootInheritanceEntity();
      String inheritance = getInheritance(root);
      // Are we the subclass element
      result = root.getFullyQualifiedName().equals(
      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;

      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">

      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.




            • Assignee:
              overheat Plushnikov Michail
              mattes3 Matthias Bohlen
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: