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

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

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


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

class TbSale
{
  Integer id;
  TbProduct product;
  TbClient client;
  Float productAmount;
  Float totalPaid;
}


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

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


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


这样通过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经验的朋友,看看怎么解决,谢谢.

你可能感兴趣的:(数据结构,sql,Hibernate,F#)