『提問』聯合主鍵(compsite-id)所引起的問題

Travelsky發表於2005-01-27
A表中first、second 作為主鍵 同時也是B表的聯合主鍵。原有系統還在使用,不能做修改。所以新建ID列的方法在此不能用。請問如何編寫hbm檔案
3x
A表 B表
first --------------------------------> first
second----------------------------->second
name item
配置檔案:
A.hbm.xml

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > 

<hibernate-mapping package="com.travelsky.poc"> 
<class name="A" table="A"> 
<composite-id > 
<key-property column="FIRST" name="First" type="integer" /> 
<key-property column="SECOND" name="Second" 
type="integer" /> 
</composite-id > 

<property column="NAME" name="Name" type="string" /> 

</class> 
</hibernate-mapping> 
<p class="indent">

B.hbm.xml

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > 

<hibernate-mapping package="com.travelsky.poc"> 
<class name="B" table="B"> 
<composite-id > 
<p class="indent">[b]此處改如何填寫 [/b]
</composite-id > 

<property column="NAME" name="Name" type="string" /> 
</class> 
</hibernate-mapping> 
<p class="indent">

相關文章