To map a database view with no primary key, in hibernate xml mapping

久未见 提交于 2019-11-30 04:59:27

问题


I have created a view which will be used for fetching the data only(readonly)

View : Grid_View

> My Hibernate hbm file

<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>

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

> My Question

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


回答1:


You have two options either add Composite Key or add

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

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



来源:https://stackoverflow.com/questions/15829848/to-map-a-database-view-with-no-primary-key-in-hibernate-xml-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!