hibernate映射视图的两种方式

[b]1.数据库已经建立视图,hibernate只是把视图当作普通的表来映射。[/b]
视图VIEW_MER_INST_POS:
select MER.DAYS_MERCHT_ID MER_ID,
INST.DAYS_MERCHT_ID INST_ID,
POS.POS_ID POS_ID
from tbl_days_mercht_attr MER,
tbl_days_mercht_info INST,
tbl_days_mercht_pos_info POS
where MER.days_mercht_id = INST.up_days_mercht_id
and INST.days_mercht_id = POS.days_mercht_id

hbm.xml配置
<class
name="db.po.ViewMerInstPos"
table="VIEW_MER_INST_POS"
>

<composite-id>
<key-property
name="merId"
column="MER_ID"
type="java.lang.String"
length="8"
/>
<key-property
name="instId"
column="INST_ID"
type="java.lang.String"
length="8"
/>
<key-property
name="posId"
column="POS_ID"
type="java.lang.String"
length="8"
/>
</class>
</hibernate-mapping>

[b]2.数据库没有视图,用hibernate自己做视图映射[/b]
hbm配置如下:
<hibernate-mapping package="huntersxp.db.pojo">
<class name="ViewMerInstPos">
<meta attribute="sync-DAO">false</meta>
<subselect>
select
MER.DAYS_MERCHT_ID MER_ID,INST.SHOP_NM SHOP_NM,POS.POS_ID POS_ID
from tbl_days_mercht_attr MER,
tbl_days_mercht_info INST,
tbl_days_mercht_pos_info POS
where MER.days_mercht_id = INST.up_days_mercht_id and INST.days_mercht_id = POS.days_mercht_id
</subselect>
<synchronize table="tbl_days_mercht_attr"/>
<synchronize table="tbl_days_mercht_info"/>
<synchronize table="tbl_days_mercht_pos_info"/>
<composite-id>
<key-property
name="merId"
column="MER_ID"
type="java.lang.String"
length="8"
/>
<key-property
name="shopNm"
column="SHOP_NM"
type="java.lang.String"
length="40"
/>
<key-property
name="posId"
column="POS_ID"
type="java.lang.String"
length="40"
/>
</composite-id>
</class>
</hibernate-mapping>
其中synchronize表示当表的数据发生变化的时候,视图的数据也会发生变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值