I have a bag whose structure looks like this:
<bag name="foo" fetch="select" table="table_of_foos">
<key column="foo_ids"/>
<many-to-many class="Bar" column="bar_ids"/>
</bag>
My “table_of_foos” table has two columns: “foo_ids” and “bar_ids”, neither of which is unique. I want to add another column to this table that holds some information about the relationship of foos to bars, so that my table would hold three columns. Then, I want to be able to access this information in my webapp.
Unfortunately, it doesn’t seem as if I can add a property or an element to the bag. What I want to do is something like this:
<bag name="foo" fetch="select" table="table_of_foos">
<key column="foo_ids"/>
<many-to-many class="Bar" column="bar_ids"/>
<element column="still_valid" type="integer"/>
</bag>
What is the best way to accomplish this?
If your joined Table needs an additional column other than its (composite) primary-key, you must implement an additional joined class.
The joined class (which needs a composite primary key – implemented as a static inner class) is described as follows
re-write your mapping as
And FooBar mapping
If you want, you can also map a composite element instead of a joined class (A component element does not need a (composite) primary key and has its has its lifecycle bound to that of its owning Entity instance. Keep this in mind)
Create you composite element (now without identifier)
And define the following mapping