Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 751
Dev Avatar asked Apr 05 '13 09:04

Dev


1 Answers

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.

like image 97
commit Avatar answered Oct 02 '22 22:10

commit