Hibernate <joined-subclass> mapping generates superfluous *.hbm.xml files
-------------------------------------------------------------------------
Key: SPRING-31
URL: http://thecla.homeftp.net:8380/jira//browse/SPRING-31
Project: Spring Cartridge
Type: Bug
Reporter: Matthias Bohlen
Assigned to: Chad Brandon
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.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://thecla.homeftp.net:8380/jira//secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Andromda-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/andromda-devel