<class name="Person">
<id name="id" column="personId">
<generator class="native" />
</id>
<set name="addresses" table="PersonAddress">
<key column="personId" />
<many-to-many column="addressId" unique="true" class="Address" />
</set>
</class>
<class name="Address">
<id name="id" column="addressId">
<generator class="native" />
</id>
<join table="PersonAddress" inverse="true" optional="true">
<key column="addressId" />
<many-to-one name="person" column="personId" not-null="true" />
</join>
</class>
DDL:
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null, addressId bigint not null primary key )
create table Address ( addressId bigint not null primary key )
这样就可在many-to-one的情况下使用中间表了,且不需要中间表对应的entity . hibernate文档上貌似说此种方法不好
表的个数要小于实体的个数才可以????