I need to map a pretty big model with well over 100 classes and polymorphic associations are causing problems. The picture shows a simplified class diagram.
I use a "table per subclass" mapping which is slightly better than "table per concrete class", so every class and interface gets a table. At least one parent interface (RootModelElement) is mapped correctly and polymorphic associations work from this side.
As the classes A and B already have a super class, the ReferenceKeeper interface is lost in my mapping. Something like
extends="demomodel.RootModelElement,demomodel.ReferenceTarget" would be super awesome.
How can I fix the mapping?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false">
<class name="demomodel.impl.ContainerImpl" entity-name="demomodel.Container" abstract="false" lazy="false" table="`demomodel_container`">
<meta attribute="eclassName" inherit="false">Container</meta>
<meta attribute="epackage" inherit="false">http://asdf.mappingdemo.org/demomodel/V1.0</meta>
<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
<meta attribute="syntheticId" inherit="false">true</meta>
<generator class="native"/>
</id>
<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
<meta attribute="syntheticVersion" inherit="false">true</meta>
</version>
<list name="elements" lazy="true" cascade="all,delete-orphan">
<key update="true">
<column name="`rootmodelelement_container_e_id`" unique="false"/>
</key>
<list-index column="`container_elements_idx`"/>
<one-to-many entity-name="demomodel.RootModelElement"/>
</list>
</class>
<class name="demomodel.impl.RootModelElementImpl" entity-name="demomodel.RootModelElement" abstract="true" lazy="false" table="`demomodel_rootmodelelement`">
<meta attribute="eclassName" inherit="false">RootModelElement</meta>
<meta attribute="epackage" inherit="false">http://asdf.mappingdemo.org/demomodel/V1.0</meta>
<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
<meta attribute="syntheticId" inherit="false">true</meta>
<generator class="native"/>
</id>
<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
<meta attribute="syntheticVersion" inherit="false">true</meta>
</version>
<property name="name" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
<column not-null="false" unique="false" name="`rootmodelelement_name`"/>
</property>
<many-to-one name="container" entity-name="demomodel.Container" lazy="false" cascade="merge,persist,save-update,lock,refresh" foreign-key="demomodel_rootmodelelement_container" insert="false" update="false" not-null="false">
<column not-null="false" unique="false" name="`rootmodelelement_container_e_id`"/>
</many-to-one>
</class>
<joined-subclass name="demomodel.impl.AImpl" entity-name="demomodel.A" abstract="false" lazy="false" extends="demomodel.RootModelElement" table="`demomodel_a`">
<meta attribute="eclassName" inherit="false">A</meta>
<meta attribute="epackage" inherit="false">http://asdf.mappingdemo.org/demomodel/V1.0</meta>
<key>
<column name="`demomodel_rootmodelelement_e_id`"/>
</key>
</joined-subclass>
<joined-subclass name="demomodel.impl.BImpl" entity-name="demomodel.B" abstract="false" lazy="false" extends="demomodel.RootModelElement" table="`demomodel_b`">
<meta attribute="eclassName" inherit="false">B</meta>
<meta attribute="epackage" inherit="false">http://asdf.mappingdemo.org/demomodel/V1.0</meta>
<key>
<column name="`demomodel_rootmodelelement_e_id`"/>
</key>
</joined-subclass>
<class entity-name="demomodel.ReferenceTarget" abstract="true" lazy="false" table="`demomodel_referencetarget`">
<meta attribute="eclassName" inherit="false">ReferenceTarget</meta>
<meta attribute="epackage" inherit="false">http://asdf.mappingdemo.org/demomodel/V1.0</meta>
<id type="long" name="e_id" column="e_id" access="org.eclipse.emf.teneo.hibernate.mapping.identifier.IdentifierPropertyHandler">
<meta attribute="syntheticId" inherit="false">true</meta>
<generator class="native"/>
</id>
<version name="e_version" column="e_version" access="org.eclipse.emf.teneo.hibernate.mapping.property.VersionPropertyHandler">
<meta attribute="syntheticVersion" inherit="false">true</meta>
</version>
</class>
<joined-subclass name="demomodel.impl.ReferenceKeeperImpl" entity-name="demomodel.ReferenceKeeper" abstract="false" lazy="false" extends="demomodel.RootModelElement" table="`demomodel_referencekeeper`">
<meta attribute="eclassName" inherit="false">ReferenceKeeper</meta>
<meta attribute="epackage" inherit="false">http://asdf.mappingdemo.org/demomodel/V1.0</meta>
<key>
<column name="`demomodel_rootmodelelement_e_id`"/>
</key>
<many-to-one name="refTarget" entity-name="demomodel.ReferenceTarget" lazy="false" cascade="merge,persist,save-update,lock,refresh" foreign-key="demomodel_referencekeeper_reftarget" insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`referencetarget_reftarget_e_id`"/>
</many-to-one>
</joined-subclass>
</hibernate-mapping>
This is the simplified ecore model.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="demomodel" nsURI="http://asdf.mappingdemo.org/demomodel/V1.0"
nsPrefix="demomodel">
<eClassifiers xsi:type="ecore:EClass" name="Container">
<eStructuralFeatures xsi:type="ecore:EReference" name="elements" upperBound="-1"
eType="#//RootModelElement" containment="true" eOpposite="#//RootModelElement/container"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="RootModelElement" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="container" eType="#//Container"
eOpposite="#//Container/elements"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="A" eSuperTypes="#//RootModelElement #//ReferenceTarget"/>
<eClassifiers xsi:type="ecore:EClass" name="B" eSuperTypes="#//RootModelElement #//ReferenceTarget"/>
<eClassifiers xsi:type="ecore:EClass" name="ReferenceTarget" abstract="true"/>
<eClassifiers xsi:type="ecore:EClass" name="ReferenceKeeper" eSuperTypes="#//RootModelElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="refTarget" eType="#//ReferenceTarget"/>
</eClassifiers>
</ecore:EPackage>