开发者

hibernate mapping for list of classes

开发者 https://www.devze.com 2023-02-20 11:54 出处:网络
I have a class A{a_id,other properties List) and class B{b_id,other properties). I have different tables for A and B and mapping table A_B(a_id,b_id,displayorder).Entries in table are constant . We ca

I have a class A{a_id,other properties List) and class B{b_id,other properties). I have different tables for A and B and mapping table A_B(a_id,b_id,displayorder).Entries in table are constant . We can insert/update/delete from table A. I try to map it in hibernate using list but it is not inserting any row in A_B开发者_高级运维. What should be the ideal way to map above scenario.

<class name="A" table="A"> 
    <id name="templateKey" column="templateKey"> 
        <generator class="native" /> 
     </id> 
    <property name="id" column="id"/> 
    <property name="name" column="name"/> 
    <list name="selectedColumns" table="A_B"> 
        <key column="templateKey"/> 
        <list-index column="displayOrder"/> 
        <one-to-many class="B" /> 
    </list> 
</class> 
<class name="B" table="B"> 
    <id name="columnKey" column="columnKey"> 
        <generator class="native" /> 
    </id> 
    <property name="displayName" column="displayName" /> 
</class>


change your hbm file for A like this. You missed Cascade in A's hbm file which is why I suspect its no inserting in A_B.

<class name="A" table="A">
        <id name="templateKey" column="templateKey">
            <generator class="native" />
        </id>
        <property name="id" column="id" />
        <property name="name" column="name" />
        <list name="selectedColumns" table="A_B" cascade="all">
            <key column="templateKey" />
            <list-index column="displayOrder" />
            <one-to-many class="B" />
        </list>
    </class>
0

精彩评论

暂无评论...
验证码 换一张
取 消