Hibernate version: 3.1.3
Name and version of the database you are using: DB2 v8.1
hibernatetools version: 3.1.0.beta5
Hi, I want to override existing primary keys.
There are three primary-keys, A_PK1_SEQ, A_PK2_SEQ, A_PK3_SEQ, in TABLE_A, and another table, TABLE_B, has four primary-keys, A_PK1_SEQ, A_PK2_SEQ, A_PK3_SEQ, B_PK1_SEQ.
(The A_PK1_SEQ, A_PK2_SEQ, A_PK3_SEQ keys in TABLE_B are also FK from TABLE_A.)
But, I just want to use one PK(A_PK1_SEQ) for TABLE_A, and one PK(B_PK1_SEQ) with FK(A_PK1_SEQ) for TABLE_B.
This is my reverse engineering file:
Code:
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Integer" />
.....
</type-mapping>
<table-filter match-name="TABLE_A" />
<table-filter match-name="TABLE_B" />
<table name="TABLE_A">
<primary-key>
<generator class="assigned" />
<key-column name="A_PK1_SEQ" />
</primary-key>
</table>
<table name="TABLE_B">
<primary-key>
<generator class="assigned" />
<key-column name="B_PK1_SEQ" />
</primary-key>
<foreign-key constraint-name="B_A" foreign-table="TABLE_A">
<column-ref local-column="A_PK1_SEQ" foreign-column="A_PK1_SEQ" />
<many-to-one property="a" />
<set property="b" />
</foreign-key>
</table>
</hibernate-reverse-engineering>
Generated table_a.hbm.xml:
There are two sets of table_b. One is new with one PK and the other is using existing constraint with three PKs.
Code:
<hibernate-mapping>
<class name="Table_a" table="TABLE_A">
<composite-id name="id"
class="Table_aId">
<key-property name="aPk1Seq" type="java.lang.Integer">
<column name="A_PK1_SEQ" />
</key-property>
<key-property name="aPk2Seq" type="java.lang.Integer">
<column name="A_PK2_SEQ" />
</key-property>
<key-property name="aPk3Seq" type="java.lang.Integer">
<column name="A_PK3_SEQ" />
</key-property>
</composite-id>
<property ....... />
<set name="bForFkf2dfd3da76fc2df0" inverse="true">
<key>
<column name="A_PK1_SEQ" not-null="true" />
<column name="A_PK2_SEQ" not-null="true" />
<column name="A_PK3_SEQ" not-null="true" />
</key>
<one-to-many class="table_b" />
</set>
<set name="b" inverse="true">
<key>
<column name="A_PK1_SEQ" not-null="true" />
</key>
<one-to-many class="table_b" />
</set>
</class>
</hibernate-mapping>
Generated table_b.hbm.xml,
Code:
<hibernate-mapping>
<class name="Table_b" table="TABLE_B">
<composite-id name="id" class="Table_bId">
<key-property name="aPk1Seq" type="java.lang.Integer">
<column name="A_PK1_SEQ" />
</key-property>
<key-property name="aPk2Seq" type="string">
<column name="A_PK2_SEQ" type="java.lang.Integer" />
</key-property>
<key-property name="aPk3Seq" type="java.lang.Integer">
<column name="A_PK3_SEQ" />
</key-property>
<key-property name="bPk1Seq" type="java.lang.Integer">
<column name="B_PK1_SEQ" />
</key-property>
</composite-id>
<many-to-one name="aByFkf2dfd3da76fc2df0" class="Table_a" update="false" insert="false" fetch="select">
<column name="A_PK1_SEQ" not-null="true" />
<column name="A_PK2_SEQ" not-null="true" />
<column name="A_PK3_SEQ" not-null="true" />
</many-to-one>
<many-to-one name="a" class="Table_a" update="false" insert="false" fetch="select">
<column name="A_PK1_SEQ" not-null="true" />
</many-to-one>
<property ..... />
</class>
</hibernate-mapping>
What I want:
table_a.hbm.xml:
Code:
<hibernate-mapping>
<class name="table_a" table="TABLE_A">
<id name="aPk1Seq" type="java.lang.Integer">
<column name="A_PK1_SEQ" />
<generator class="assigned" />
</id>
<property ....... />
<set name="b" inverse="true">
<key>
<column name="A_PK1_SEQ" not-null="true" />
</key>
<one-to-many class="table_b" />
</set>
</class>
</hibernate-mapping>
table_b.hbm.xml:
Code:
<hibernate-mapping>
<class name="Table_b" table="TABLE_B">
<id name="bPk1Seq" type="java.lang.Integer">
<column name="B_PK1_SEQ" />
<generator class="assigned" />
</id>
<many-to-one name="a" class="Table_a" update="false" insert="false" fetch="select">
<column name="A_PK1_SEQ" not-null="true" />
</many-to-one>
<property ..... />
</class>
</hibernate-mapping>
Is it possible to get above hbm.xml without changing real DB schema?
Can I override existing constraints?
I would appreciate any comment and hints.
Thanks.