hibernate相同主键的关联

对于已经存在的数据库系统,我们可能遇到这种情况
table Report_CAC:
REPORTID primary key
RPTCONTENT
......
table Report_SASP:
REPORTID primary key
RECEIVETIME
INSERTTIME
TT
2个表的主键完全相同,如果Report_SASP想读取Report_CAC中相同的REPORTID的RPTCONTENT,普通的sql比较好写,但是hibernate就要麻烦点,思路如下
ReportSASP类中添加一个属性reportContent,配置文件中 insert="false" update="false"

映射文件可以这样:
    <class name="ReportCAC" table="Report_CAC">
        <id name="reportId" type="string" column="REPORTID" length="26"></id>
        <property name="reportContent" type="clob" column="RPTCONTENT"
            not-null="true" />
  ......
    </class>

    <class name="ReportSASP" table="Report_SASP">
        <id name="reportId" type="string" column="REPORTID" length="26"></id>
        <many-to-one name="reportContent" column="REPORTID" class="WDBOpmetPointCAC" insert="false" update="false"
            not-null="true"/>
        <property name="receiveTime" type="date" column="RECEIVETIME"
            not-null="true" />
        <property name="insertTime" type="date" column="INSERTTIME"
            not-null="true" />
        <property name="tt" type="string" column="TT" length="2"
            not-null="true" />
  ......
    </class>
posted @ 2009-09-16 16:17  风间  阅读(235)  评论(0编辑  收藏  举报