我有一个由Hibernate映射的一对多关系中的两个表:
<hibernate-mapping>
<class name="Class1" table="TABLE_1" dynamic-update="true">
<meta attribute="implement-equals">true</meta>
<cache usage="read-write"/>
<id name="id" column="KEY_1" length="5" >
....
</id>
<property name="property1a" column="COLUMN_1A" type="string" length="10" />
<property name="property1b" column="COLUMN_1B" type="string" length="10" />
<set name="properties2Set" table="TABLE_2" lazy="true" fetch="subselect" cascade="all">
<key column="FOREIGN_KEY_1"/>
<composite-element class="Class2">
<property name="property2a" type="string" column="COLUMN_2A"/>
<property name="property2b" type="string" column="COLUMN_2B"/>
<property name="property2c" type="string" column="COLUMN_2C"/>
</composite-element>
</set>
</class>
</hibernate-mapping>
Class1看起来像:
public class Class1
{
//... Here the definitions of property1a, property1b
private Set<Class2> properties2Set = new HashSet<Class2>();
public Set<Class2> getProperties2Set()
{
return properties2Set;
}
public void setProperties2Set(Set<Class2> properties2Set)
{
this.properties2Set = properties2Set;
}
// ... Definitions of equals() and hashCode()
}
Class2包含属性property2a, property2b, property2c
。有一个约束
CONSTRAINT PK_OLD PRIMARY KEY (FOREIGN_KEY_1, COLUMN_2A, COLUMN_2B, COLUMN_2C)
我想在表中添加列
COLUMN_ID_NUMBER NUMBER(5) DEFAULT 0 NOT NULL
将约束更改为
CONSTRAINT PK_NEW PRIMARY KEY (FOREIGN_KEY_1, COLUMN_ID_NUMBER)
并生成COLUMN_ID_NUMBER
的值,以免违反约束。
在何处添加将映射到COLUMN_ID_NUMBER
的属性以及如何生成其值?是否可以保持Class2
的结构不变?