-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Bidirectional join-table relationship doesn't work
PostPosted: Fri Jan 08, 2010 9:38 pm 
Newbie

Joined: Mon Oct 04, 2004 5:09 pm
Posts: 4
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.