求一种Hibernate的对象的关系的设计

现在有一个TbFinancial的VO,存入账出账的记录

[code]
class TbFinancial
{
Integer id ,fk_id;
String type ;
Float number; //这里是入账或出账的金额
}
[/code]

有一个TbSale, 存门市的销售记录

[code]
class TbSale
{
Integer id;
TbProduct product;
TbClient client;
Float productAmount;
Float totalPaid;
}
[/code]

如果从表的关系来说, financial表是通过type和fk_id字段, 来关联到sale表的某条记录, 从而计算出入账或出出账数目的,sql如下:

[code]
select fk_id,type from financial f where type='门市销售' left outter join (select * from sales s) where f.fk_id=s.id
[/code]

如果financial表关联到退货记录表 refund ,sql就是这样的
[code]
select fk_id,type from financial f where type='退货记录' left outter join (select * from refund r) where f.fk_id=r.id
[/code]

这样通过type和fk_id来与其它表连接的话,就保证了financial表的通用性, 但是用sql就容易搞定,如果转成Hibernate对象,遇到两个问题

1 TbFinancial对象的属性中,应该包括其它表的VO, 但这个VO的类型是不确定的,有可能是TbSale, 有可能是TbRefund,这怎么配置呢?

2 TbFinancial对象和其它VO的关系, 不是one-to-many, 也不是many-to-one, 也不是many-to-many,是one-to-one吗?

像这种问题, 请教一下有丰富hibernate经验的朋友,看看怎么解决,谢谢.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值