如何在hibernate使用原有的主键字段,而不是重新生成一个ID来替代原有的主键

wolf 03-08-07


<hibernate-mapping>
<class name="Group" table="GROUP">
<id name=
"id" column="ID"><!-- 用原有的主键字段代替 -->
<generator class=
"identity">
</generator>
</id>
<discriminator column=
"GROUP"/>
<property name=
"name" type="java.lang.String" column="NAME" not-null="true" unique="false"/>
<property name=
"description" type="java.lang.String" column="DESCRIPTION" not-null="false" unique="false"/>
<set name=
"roles" table="ROLE_GROUP" lazy="false" cascade="none" sort="unsorted">
<key column=
"GROUP_ID"/>
<many-to-many class=
"Role" column="ROLE_ID"/>
</set>
<set name=
"users" table="GROUP_USER" lazy="false" cascade="none" sort="unsorted">
<key column=
"GROUP_ID"/>
<many-to-many class=
"User" column="USER_ID"/>
</set>
<set name=
"children" table="GROUP" inverse="false" lazy="false" cascade="all">
<key column=
"PARENT"/>
<one-to-many class=
"Group"/>
</set>
<many-to-one name=
"parent" class="Group" column="PARENT" not-null="false" unique="false" cascade="none" outer-join="auto"/>
<subclass name=
"database.DefaultGroup" discriminator-value="DEFAULT_GROUP"/>
</class>
</hibernate-mapping>

yehs220
2003-08-07 10:52

<id name="id" column="ID"><!-- 用原有的主键字段代替 --> <generator class="identity"> </generator> </id>

class="identity" 改为 class="assigned"