access data from two table

谁说我不能喝 提交于 2020-01-05 08:21:32

问题


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.

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>

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


回答1:


You can use either SELECT JOIN SQL query when reading the data, and ON UPDATE CASCADE SQL queries when creating/updating data.




回答2:


Don't do it like this. Just

  • create a entity class Form
  • define a one-to-one relationship in your hbm.xml, between Customer and Form
  • create a property Form form in your Customer class
  • define a method in your DAO or whatever to return you name and value as a map.


来源:https://stackoverflow.com/questions/3976087/access-data-from-two-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!