我有两个类Hibernate的一对一的映射
Class Item
{
private Auction CorrespondingAuction;
}
Class Auction
{
private Item CurrentItem;
}
谁能告诉我该如何设置一个以XML一对一的映射,它必须是双向的
我有两个类Hibernate的一对一的映射
Class Item
{
private Auction CorrespondingAuction;
}
Class Auction
{
private Item CurrentItem;
}
谁能告诉我该如何设置一个以XML一对一的映射,它必须是双向的
已经生成在拍卖XML文件中的ID采取:
<many-to-one name="CurrentItem" class="com.BiddingSystem.Models.Item" fetch="join"
not-null="true" cascade="all" unique="true" lazy="false">
<column name="CURRENTITEM" />
</many-to-one>
在项目XML文件:
<one-to-one name="auction" class="com.BiddingSystem.Models.Auction" property-ref="CurrentItem"/>
property-ref指与拍卖类中类商品相对应的变量的名称
书签this cheat sheet。这显示了所有简单的例子Hibernate支持的映射。
你需要有PK的共同点:
Class Item {
@Id
Long id;
@OneToOne
private Auction CorrespondingAuction;
}
Class Auction {
@Id
Long id;
private Item CurrentItem;
}
用于拍卖的ID是从项目
我正在使用xml映射 – Noor 2011-01-08 15:03:05
对其他人:这是一个很好的参考,但它是基于XML的。 – ArtB 2011-03-22 21:10:09