论坛首页 Web前端技术论坛

JPA 中注解一个父类中多个子类实现查询部分子类方法解决方法

浏览 1998 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2010-01-09  

  父类:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING)
public class SettleBill extends PersistenceSupport {

 

子类:

@Entity
@DiscriminatorValue("SupplierVacationBill")
public class SupplierVacationBill extends SettleBill ;

 

@Entity
@GenericGenerator(name = "seq_gen", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {@Parameter(name = "sequence_name", value = "seq_SupplierFlightBill"), @Parameter(name = "initial_value", value = "100000")})
public class SupplierFlightBill extends SettleBill;

 

 

@Entity
@GenericGenerator(name = "seq_gen", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {@Parameter(name = "sequence_name", value = "seq_SupplierHotelBill"), @Parameter(name = "initial_value", value = "100000")})
public class SupplierHotelBill extends SettleBill;

 

@Entity
@GenericGenerator(name = "seq_gen", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {@Parameter(name = "sequence_name", value = "SEQ_SETTLE_BILL"), @Parameter(name = "initial_value", value = "100000")})
public class SameTradeFlightBill extends SettleBill;

 

 

查询其中SupplierFlightBill ,SupplierHotelBill ,SupplierVacationBill  但是不查询SameTradeFlightBill 一次性查询:

本人解决方案:

 DynamicQuery dquery = new DynamicQuery(" select distinct  vb from " + searchCondition.getForTypeName() + " vb ");

 

// 设置查询的辨别列名称
    dquery.append("and (");
    dquery.append(" vb.class=SupplierFlightBill or vb.class=SupplierHotelBill or vb.class=SupplierVacationBill ");
    dquery.append(" )");

 

 

 

请问高人有没有更简单的解决方案!本人认为自己的解决方案不够好!希望给出解决方案!!

 

论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics