Many to one for Nullable foreign keys
A unidirectional many-to-one association on a join table is common when the association is optional. For example:
<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
<join table="PersonAddress"
optional="true">
<key column="personId" unique="true"/>
<many-to-one name="address"
column="addressId"
not-null="true"/>
</join>
</class>
<class name="Address">
<id name="id" column="addressId">
<generator class="native"/>
</id>
</class>
create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null primary key, addressId bigint not null )
create table Address ( addressId bigint not null primary key )
ref: https://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch08.html
猜你喜欢
转载自jsfcoder.iteye.com/blog/2147826
今日推荐
周排行