要映射没有主键的数据库视图,在 hibernate xml 映射中 [英] To map a database view with no primary key, in hibernate xml mapping

查看:31
本文介绍了要映射没有主键的数据库视图,在 hibernate xml 映射中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个仅用于获取数据的视图(只读)

视图:Grid_View

View : Grid_View

>我的 Hibernate hbm 文件

<hibernate-mapping>   
     <class name="hibernate.domain.View" table="Grid_View" mutable="false">
         <property name="ACCT_BR_CD" type="string">
            <column name="ACCT_BR_CD"/>
        </property>
        <property name="ACCT_NO" type="string">
            <column name="ACCT_NO"/>
        </property>
        <property name="LGL_ENTY_NM" type="string">
            <column name="LGL_ENTY_NM"/>
        </property>
        <property name="CUST_CTRY_CD" type="string">
            <column name="CUST_CTRY_CD"/>
        </property>
        <property name="ACCT_SRC_SYS_CD" type="string">
            <column name="ACCT_SRC_SYS_CD"/>
        </property>    
    </class>
</hibernate-mapping>

> 因为在我看来它们不是主键,所以我没有在我的映射中提到 id 字段.但是在hibernate中需要id.

> As their is no primary key in my view,Ihave not mentioned id field in my mapping. But in hibernate id is required.

>我的问题

如何在休眠映射文件中进行没有 id 的映射.并且它们没有具有唯一值的列,因此它们没有任何机会使它们成为键.请帮我解决这个问题

How to proceed with the mapping without id in the hibernate mapping file. And their are no columns with unique values so thier is no any chance of making them the key. Please help me resolve this issue

推荐答案

您有两种选择:添加复合键或添加

You have two options either add Composite Key or add

<id column="ROWID" type="string" />

Hibernate 需要唯一的键来映射.最好的方法是添加主键.

Hibernate need unique key to map. Best approach is to add primary key.

这篇关于要映射没有主键的数据库视图,在 hibernate xml 映射中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆