How to query two SQL tables with the same structure using criteria api?

I have an Archive database where there are 2 tables with the same structure, EvntSumaryT which is active and ArchiveEvntSumaryT which is the archived. I want to change my current criteria api code which only queries EvntSumary so that it will fetch data from both tables based on the user selected dates and return the results into a list. My problem is that their is no Union feature in hibernate-criteria so how would I be able to query both tables at once and combine the results into a list?

Below is the code for my jpa entity classes. I've set up the active table's entity as the parent class and the child as ArchiveEvntSumaryT which extents from it since they share the same fields.

@Entity
@Table(name="EVNT_SUMARY_T")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class EvntSumaryT {
    //fields 
    //getters and setters
}

@Entity
@Table(name="ARCHIVE_EVNT_SUMARY_T")
public class ArchiveEvntSumaryT extends EvntSumaryT {


}

And this is my criteria api query in the DAO class before archiving the database.

public List<EvntSumaryT> getAllTransaction(SearchCriteria sb) {
    //criteria
    return ls;

}

How would I be able to query both tables and return the results into a list without the Union function?


I figured it out. Instead of using inhertance to replace the union function I ended up creating a view in the database that's the union of the two tables and mapped the entity to the view.

链接地址: http://www.djcxy.com/p/37084.html

上一篇: 休眠标准一对多问题

下一篇: 如何使用条件api查询两个具有相同结构的SQL表?