7

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

Dev
  • 3,922
  • 3
  • 24
  • 44

1 Answers1

4

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.

commit
  • 4,777
  • 15
  • 43
  • 70
  • 1
    Then you can add one "Auto Increment" column in table, It is best approach because hibernate had many functionality would not work without unique id like findById method and mapping between tables, That's why hibernate force to make ID. And in the option of ID you can add composite key and include all column in that composite key, than it will work. – commit Apr 05 '13 at 09:56