このマッピングの問題について教えてください(私はHibernate 3.6を使用しています)。
私はこれらのテーブルを持っています
CREATE TABLE Towers (
Id INT NOT NULL AUTO_INCREMENT ,
Name VARCHAR(5) NOT NULL ,
PRIMARY KEY (Id));
CREATE TABLE LineOfBusiness (
Id INT NOT NULL AUTO_INCREMENT,
Name VARCHAR(15) NOT NULL ,
PRIMARY KEY (Id));
CREATE TABLE LineOfBusinessXTowers (
LineOfBusinessId INT NOT NULL ,
TowerId INT NOT NULL ,
PRIMARY KEY (LineOfBusinessId, TowerId));
CREATE TABLE IF NOT EXISTS Departments (
Code INT NOT NULL ,
LineOfBusinessId INT NOT NULL ,
TowerId INT NOT NULL ,
PRIMARY KEY (Code));
ALTER TABLE LineOfBusinessXTowers
ADD CONSTRAINT FK_LineOfBusinessXTowers_LineOfBusiness
FOREIGN KEY (LineOfBusinessId)
REFERENCES LineOfBusiness (Id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
ADD CONSTRAINT FK_LineOfBusinessXTowers_Towers
FOREIGN KEY (TowerId)
REFERENCES Towers (Id)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
ALTER TABLE Departments
ADD CONSTRAINT FK_Departments_LineOfBusinessXTowers
FOREIGN KEY (LineOfBusinessId, TowerId)
REFERENCES LineOfBusinessXTowers (LineOfBusinessId,TowerId)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
Hibernateマッピングクラスに、対応するTowerオブジェクトとLineOfBusinessオブジェクトを持つDepartmentクラスが必要です。
public class Departments {
private int code;
private String name;
private LineOfBusiness lineOfBusiness;
private Towers tower;
//Constructors and access methods here
}
私はこの方法でマッピングを行おうとしていましたが、間違っています:
<hibernate-mapping>
<class name="Departments" table="Departments" catalog="DB">
<id name="code" type="int">
<column name="Code" />
<generator class="assigned" />
</id>
<property name="name" type="string">
<column name="Name" length="45" not-null="true" unique="true" />
</property>
<join table="LineOfBusinessXTowers" optional="false">
<key column="LineOfBusinessId" unique="false" />
<many-to-one name="lineOfBusiness"
class="LineOfBusiness">
<column name="LineOfBusinessId" not-null="true" />
</many-to-one>
</join>
<join table="LineOfBusinessXTowers" optional="false">
<key column="TowerId" unique="false" />
<many-to-one name="towers" class="Towers">
<column name="TowerId" not-null="true" />
</many-to-one>
</join>
</class>
</hibernate-mapping>
私がやりたいことをするための正しいマッピングはどれですか?できますか?別のより良い戦略はありますか?
どうもありがとうございました。
アテ:エドガー