我的数据库表结构如下: 
UUID NOT NULL NUMBER 
TPNAME VARCHAR2(100) 
USERLABEL VARCHAR2(2000) 
NATIVEEMSNAME VARCHAR2(64) 
OWNER VARCHAR2(64) 
TPTYPE VARCHAR2(16) 
CONNECTIONSTATE VARCHAR2(32) 
DIRECTION VARCHAR2(16) 
TRANSMISSIONPARAMS VARCHAR2(64) 
TPPROTECTIONASSOCIATION VARCHAR2(16) 
EDGEPOINT NUMBER 
PTPID NUMBER 
MEID NUMBER 
TPMAPINGMODE VARCHAR2(64) 
REMARK VARCHAR2(255) 
EQUIPMENTID NUMBER 
PROFESSIONALTYPE VARCHAR2(64) 
POSITION NUMBER 
PARAM VARCHAR2(255) 这个表利保存着ptp和ctp的信息,他们的信息基本相同,其中ptp是ctp的父亲节点,ctp通过ptpid,和ptp的uuid进行关联。 
我的hibernate映射文件是这样的: 
ptp的映射文件: 
?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="com.metarnet.cms.entities"> 
<class 
name="ResPtp" 
table="RES_TP" 
where="TPTYPE='PTP'" 
lazy="true" 
proxy="ResPtp" 

<meta attribute="sync-DAO">false</meta> 
<id 
name="Id" 
type="long" 
column="UUID" 
unsaved-value="0" 

<generator class="increment"/> 
</id> <property 
name="Tpname" 
column="TPNAME" 
type="string" 
not-null="false" 
length="100" 
/> 
<property 
name="Userlabel" 
column="USERLABEL" 
type="string" 
not-null="false" 
length="100" 
/> 
<property 
name="Nativeemsname" 
column="NATIVEEMSNAME" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Owner" 
column="OWNER" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Tptype" 
column="TPTYPE" 
type="string" 
not-null="false" 
length="16" 
/> 
<property 
name="Connectionstate" 
column="CONNECTIONSTATE" 
type="string" 
not-null="false" 
length="32" 
/> 
<property 
name="Direction" 
column="DIRECTION" 
type="string" 
not-null="false" 
length="16" 
/> 
<property 
name="Transmissionparams" 
column="TRANSMISSIONPARAMS" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Tpprotectionassociation" 
column="TPPROTECTIONASSOCIATION" 
type="string" 
not-null="false" 
length="16" 
/> 
<property 
name="Edgepoint" 
column="EDGEPOINT" 
type="long" 
not-null="false" 
length="22" 
/> 
<!-- 
<property 
name="Ptpid" 
column="PTPID" 
type="long" 
not-null="false" 
length="22" 
/> 
<property 
name="Meid" 
column="MEID" 
type="long" 
not-null="false" 
length="22" 
/> 
--> 
<property 
name="Tpmapingmode" 
column="TPMAPINGMODE" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Re" 
column="REMARK" 
type="string" 
not-null="false" 
length="255" 
/> 
<!-- 
<property 
name="Equipmentid" 
column="EQUIPMENTID" 
type="long" 
not-null="false" 
length="22" 
/> 
--> 
<property 
name="Professionaltype" 
column="PROFESSIONALTYPE" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Position" 
column="POSITION" 
type="long" 
not-null="false" 
length="22" 
/> 
<property 
name="Param" 
column="PARAM" 
type="string" 
not-null="false" 
length="255" 
/> <bag name="CTPList" table="RES_TP" inverse="true" lazy="true" cascade="all" where="tptype='CTP'"> 
<key column="PTPID"/> 
<one-to-many class="com.metarnet.cms.entities.ResCtp"></one-to-many> 
</bag> 
<many-to-one name="Equipment" column="EQUIPMENTID" class="com.metarnet.cms.entities.ResEquipment" ></many-to-one> 
<many-to-one name="ME" column="MEID" class="com.metarnet.cms.entities.ResMe" ></many-to-one> 
</class> 
</hibernate-mapping> ctp的映射文件: 
<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="com.metarnet.cms.entities"> 
<class 
name="ResCtp" 
table="RES_TP" 
where="TPTYPE='CTP'" 

<meta attribute="sync-DAO">false</meta> 
<id 
name="Id" 
type="long" 
column="UUID" 
unsaved-value="0" 

<generator class="increment"/> 
</id> <property 
name="Tpname" 
column="TPNAME" 
type="string" 
not-null="false" 
length="100" 
/> 
<property 
name="Userlabel" 
column="USERLABEL" 
type="string" 
not-null="false" 
length="100" 
/> 
<property 
name="Nativeemsname" 
column="NATIVEEMSNAME" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Owner" 
column="OWNER" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Tptype" 
column="TPTYPE" 
type="string" 
not-null="false" 
length="16" 
/> 
<property 
name="Connectionstate" 
column="CONNECTIONSTATE" 
type="string" 
not-null="false" 
length="32" 
/> 
<property 
name="Direction" 
column="DIRECTION" 
type="string" 
not-null="false" 
length="16" 
/> 
<property 
name="Transmissionparams" 
column="TRANSMISSIONPARAMS" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Tpprotectionassociation" 
column="TPPROTECTIONASSOCIATION" 
type="string" 
not-null="false" 
length="16" 
/> 
<property 
name="Edgepoint" 
column="EDGEPOINT" 
type="long" 
not-null="false" 
length="22" 
/> <property 
name="Tpmapingmode" 
column="TPMAPINGMODE" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Re" 
column="REMARK" 
type="string" 
not-null="false" 
length="255" 
/> <property 
name="Professionaltype" 
column="PROFESSIONALTYPE" 
type="string" 
not-null="false" 
length="64" 
/> 
<property 
name="Position" 
column="POSITION" 
type="long" 
not-null="false" 
length="22" 
/> 
<property 
name="Param" 
column="PARAM" 
type="string" 
not-null="false" 
length="255" 
/> <many-to-one name="PTP" column="PTPID" class="com.metarnet.cms.entities.ResPtp" ></many-to-one> 
<many-to-one name="Equipment" column="EQUIPMENTID" class="com.metarnet.cms.entities.ResEquipment" ></many-to-one> 
<many-to-one name="ME" column="MEID" class="com.metarnet.cms.entities.ResMe" ></many-to-one> <bag name="ctpInAendSNCList" table="RES_SNC" inverse="true" > 
<key column="AEND"/> 
<one-to-many class="com.metarnet.cms.entities.ResSnc"></one-to-many> 
</bag> <bag name="ctpInZendSNCList" table="RES_SNC" inverse="true" > 
<key column="ZEND"/> 
<one-to-many class="com.metarnet.cms.entities.ResSnc"></one-to-many> 
</bag> </class> 
</hibernate-mapping> 这样的映射给读取数据和操作ctp和ptp对象带来很大的方便,但是有一个弊端就是当保存ctp和ptp信息到数据库的时候,会发生主键冲突,我考虑可能是因为一个表映射为两个类所以,两个类的字段都是自增导致主键冲突,但是现在想了很久没有找到合适的方法(不想在数据库中建立序列,这个方法虽然行得通,但是因为需要操作不同类型的数据库,所以排除)。各位如果有兴趣,不妨研究一下。 

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【zlh218】截止到2008-07-17 08:38:54的历史汇总数据(不包括此帖):
    发帖的总数量:10                       发帖的总分数:220                      每贴平均分数:22                       
    回帖的总数量:5                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:5                        结贴的总分数:200                      
    无满意结贴数:3                        无满意结贴分:70                       
    未结的帖子数:5                        未结的总分数:20                       
    结贴的百分比:50.00 %               结分的百分比:90.91 %                  
    无满意结贴率:60.00 %               无满意结分率:35.00 %                  
    楼主加油