Reputation: 111
Excuse me for my poor english in advance as it is not my mother tongue.
Like in this example:
http://www.xylax.net/hibernate/manytomany.html
But i have in the table foo-bar 2 attributes which are not part of the primary or foreign keys.: one boolean(A) & one string(B).
I know how to map it without attributes but not in this case.
I have not found an answer in the documentation.
I need to know please how to map it & what kind of collection i have to declare in my class Foo.
Thanks in advance for your answer.
I really appreciate the time given by you.
Upvotes: 1
Views: 589
Reputation: 570285
Quoting the I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use? entry of the Hibernate Users FAQ:
Use a composite-element to model the association table. For example, given the following association table:
create table relationship ( fk_of_foo bigint not null, fk_of_bar bigint not null, multiplicity smallint, created date )
you could use this collection mapping (inside the mapping for class Foo):
<set name="relationship"> <key column="fk_of_foo"/> <composite-element class="Relationship"> <property name="multiplicity" type="short" not-null="true"/> <property name="created" type="date" not-null="true"/> <many-to-one name="bar" class="Bar" not-null="true"/> </composite-element> </set>
You may also use an
<idbag>
with a surrogate key column for the collection table. This would allow you to have nullable columns.An alternative approach is to simply map the association table as a normal entity class with two bidirectional one-to-many associations.
Upvotes: 1
Reputation: 32831
I guess you will need to create a third class to hold these attributes
Upvotes: 1