从两个表访问数据 [英] access data from two table
问题描述
客户类具有与客户表中的名称字段相对应的名称属性. 客户类还定义用于放置fieldName和fieldValue的地图.
Customer class have name property that corresponds to name field in customer table. Customer class also define the map that use for put the fieldName and fieldValue.
在数据库中,在客户表中定义客户名称,并在表单表中定义字段值. 现在,我如何从客户表中检索客户名,从表单表中检索字段值. 在hbm文件中:
on database customer name define in customer table and fieldvalue define in form table. now how i can retrieve customer name from customer table and fieldvalue from form table. in hbm file:
<map name="formFields" table="form" cascade="all-delete-orphan" lazy="true">
<key column="id"/>
<index column="fieldName" type="string"/>
<element column="fieldValue" type="string"/>
</map>
我想显示两个项目. 我有一个类别,第一项是同一类别中的属性,第二项被定义为同一类别中map函数中的映射键的映射值.两项均在单独的表上定义.如何显示两个项目
i want display two items. i have one class, first item is property in same class and second item is define as a map value of a map key in map function in same class. both items are defined on separately tables. how display both the items
推荐答案
请勿这样做.只是
- 创建实体类
Form
- 在
Customer
和Form
之间的 - 在您的
Customer
类中创建属性Form form
- 在DAO中定义一个方法或将其返回给您的
name
和value
作为映射的任何方法.
hbm.xml
中定义one-to-one
关系
- create a entity class
Form
- define a
one-to-one
relationship in yourhbm.xml
, betweenCustomer
andForm
- create a property
Form form
in yourCustomer
class - define a method in your DAO or whatever to return you
name
andvalue
as a map.
这篇关于从两个表访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!