请教hibernate union问题

如果有两个表,一个mytb,一个h_mytb,h_mytb是历史表,结构完全一样
我想在一个po里面直接影射这两个表,行吗?类似于union的功能


如果有两个表,一个mytb,一个h_mytb,h_mytb是历史表,结构完全一样
我想在一个po里面直接影射这两个表,行吗?类似于union的功能

Union is not a concept in OO world.

There are at least two solution:
1. use table-per-concrete-class strategy. Suppose A and B are the two class you want to map to table mytb and h_mytb, create superclass of A and B, say class C, and use table-per-concrete-class strategy to map the A and B to table mytb and h_mytb. You may get the "union" of class A and B by searching class C.

2. create a view based on the union of h_mytb,h_mytb and map you class to the view, this is not a perfect OO solution.

i got it .thanks a lot.it seems hibernate is going more and more complex,which is not a good tendency,i think.

使用hibernate需要思路转变,如果首先使用域模型建模,下面就比较简单。