Greetings,
I'm using Hibernate 3.2.1 and have found that the schema doesn't support the following use case:
Inheritance using table-per-subclass strategy with a bidirectional relationship using a join table.
For example:
Foo has Bar elements. I want to be able to reference Foo from any Bar element.
It so happens there are different types of Bar elements...CandyBar, IronBar, WhiskeyBar.
Here the mapping:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class abstract="true" name="Bar">
<id name="id">
<generator class="native"/>
</id>
<many-to-one column="typeId" fetch="join" lazy="false" name="type"/>
<property name="description"/>
<property name="name"/>
<join inverse="true" optional="true" table="FOO_BAR">
<key column="barId"/>
<many-to-one column="fooId" not-null="true" name="foo"/>
</join>
<joined-subclass name="ChocolateBar" table="C_BAR">
<key column="id"/>
<many-to-one column="sweetId" name="sweetTooth"/>
<property name="brush" column="brush"/>
</joined-subclass>
<joined-subclass name="IronBar" table="IRON_BAR">
<key column="id"/>
<many-to-one column="weightBenchId" fetch="join" lazy="false" name="weightBench"/>
</joined-subclass>
<joined-subclass name="WhiskeyBar" table="WHISKEY_BAR">
<key column="id"/>
<many-to-one column="kegId" fetch="join" lazy="false" name="keg"/>
</joined-subclass>
</class>
</hibernate-mapping>
I get the following error message:
Quote:
The content of element type "class" must match
"(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-
id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|
properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|
union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
It appears that you can't use "join" and "joined-subclass" in the same class mapping.
Seems like a pretty reasonable relationship.
Is there any work around? Patch? Plan to support?
Does this mean I cannot have a bidirectional relationship for this case?
Thanks for any input.