私は休止状態の世界の初心者です。アドバイスをお願いします。休止状態で 1 対 1 の関係を経験していました。私の分析によると、1 対 1 の休止状態の関係は 3 つの方法で確立できます。
1)Through Join concept
2)Same primary key in both the tables
3)Primary key and foriegn key relationship in both the tables
1 対 1 のマッピングを実現する上記の 3 つの方法が正しいか、何か不足している場合は、アドバイスしてください。また、私が使用している以下の hbm マッピング ファイルが正しいものであることも教えてください。そうでない場合は、アドバイスしてください。
1) 結合の概念を通じて:-
1 対 1 の関係を実現する 1 つの方法は、結合の概念によるものです。次の xml がそのために使用されています。
<hibernate-mapping>
<class name="mypack.Person" table="person21">
<id name="personId" type="int">
<generator class="increment">
</generator>
</id>
<property name="name"/>
<join table="personAddress">
<key column="personId"/>
<many-to-one name="address" class="mypack.Address" column="addressId" unique="true" cascade="all"/>
</join>
</class>
<class name="mypack.Address" table="address21">
<id name="id" column="addressId" type="int">
<generator class="increment"/>
</id>
<property name="city"/>
<property name="state"/>
</class>
</hibernate-mapping>
2) 両方のテーブルで同じ主キー:-
両方のテーブルで同じ主キーを使用し、次の hbm がそのために使用されています
<class name="mypack.Address" table="address31">
<id name="id" column="addressId" type="int">
<generator class="increment"/>
</id>
<property name="city"/>
<property name="state"/>
</class>
<class name="mypack.Person" table="person31">
<id name="personId" type="int">
<generator class="foreign">
<param name="property">address</param>
</generator>
</id>
<property name="name"/>
<one-to-one name="address" class="mypack.Address"/>
</class>
</hibernate-mapping>
3)両方のテーブルの主キーと外部キーの関係:-
あるテーブルの主キーと別のテーブルの外部キー。以下は、このためのhbmです
<hibernate-mapping>
<class name="mypack.Person">
<id name="personId" type="int">
<generator class="increment"/>
</id>
<property name="name"/>
<many-to-one name="address" class="mypack.Address" column="addressId" unique="true" cascade="all"/>
</class>
<class name="mypack.Address">
<id name="id" column="addressId" type="int">
<generator class="increment"/>
</id>
<property name="city"/>
<property name="state"/>
</class>
</hibernate-mapping>
人々はアドバイスしてください。