Re: Hibernate M:M mapping plus extra data in intermediary table
by Axel Hallez <Axel.Hallez@[EMAIL PROTECTED]
>
Apr 25, 2008 at 10:33 AM
Spendius wrote:
> When your middle table (that which relates your 2 tables
> through a many-to-many relation****p) contains more than
> the A_ID and B_ID columns but also -for ex.- DATE columns
> etc.- is there a way to deal with this extra info with some
> more config in your .hbm.xml files or do you really need a
> supplementary class to handle this data ?
>
> When you have no more than the 2 ID columns to deal with,
> the following mappings are enough:
> <set name="events" table="PERSON_EVENT">
> <key column="PERSON_ID"/>
> <many-to-many column="EVENT_ID" class="Event"/>
> </set>
> in a file and
> <set name="participants" table="PERSON_EVENT" inverse="true">
> <key column="EVENT_ID"/>
> <many-to-many column="PERSON_ID" class="Person"/>
> </set>
> in the other .hbm.xml file... And no specific class for the
> PERSON_EVENT database table is required - but when this
> table contains other columns, is there no way but to create
> another class to play with this extra columns ?
If you don't wrap the extra attributes in a class, how would you be able
to manage them?
If a many-to-many relation****p has extra attributes, this generally
means that the relation****p entries are entities in their own right.
Now I guess that one could come up with some schema to avoid the
definition of an extra class, but I can't imagine that this would be
easier to deal with.
Kind regards,
Axel Hallez