简体   繁体   English

Hibernate 映射 map 两列与其他表

[英]Hibernate mapping map two columns with other table

I have 2 table one is Order and other is OrderList.我有 2 个表,一个是 Order,另一个是 OrderList。

Order table is having following fields订单表有以下字段

customerId : foreign key to customer table customerId : 客户表的外键

applicationId : foreing key to application table applicationId : 应用表的外键

OrderedAt订购时间

OrderedOn已订购

OrderList table has to refer order table using applicationId and customerId and having fields: OrderList 表必须使用 applicationId 和 customerId 引用订单表并具有字段:

customerId : foreing key to Order table\ customerId : Order 表的外键\

applicationId : foreing key to Order table applicationId : Order 表的外键

OrderItem订单项

Orderprice订单价格

I want to map these two in hibernate.xml file我想 map 这两个在 hibernate.xml 文件

I am not making a seperate file for OrderList.hibernate.xml:我没有为 OrderList.hibernate.xml 创建单独的文件:

but using below code in Order.hibernate.xml itself但在 Order.hibernate.xml 本身中使用以下代码

<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?我使用正确的方法吗?

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. 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.此外,更多人可以通过注释 model 帮助您,因此您可以更快地获得答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM