Hibernate mapping map two columns with other table

Viewed 54

I have 2 table one is Order and other is OrderList.

Order table is having following fields

customerId : foreign key to customer table

applicationId : foreing key to application table

OrderedAt

OrderedOn

OrderList table has to refer order table using applicationId and customerId and having fields:

customerId: foreing key to Order table\

applicationId: foreing key to Order table

OrderItem

Orderprice

I want to map these two in hibernate.xml file

I am not making a seperate file for OrderList.hibernate.xml:

but using below code in Order.hibernate.xml itself

<list name="orders" table="Order_List" cascade="all" access="field">
            <key column="applicationId" not-null="true"/>
            <key column="customerId" not-null="true"/>
            <list-index column="OrderListIndex" />
            <composite-element class="OrderList">
                
                <property name="OrderItem" />
                <property name="OrderPrice" />
            </composite-element>
        </list>

Am I using the right way ?

1 Answers

Looks good to me, though you should switch to using JPA annotations as hbm.xml mappings are deprecated in the latest Hibernate versions and will go away at some point. Also, a lot more people can help you with the annotation model, so you would get answers faster.

Related