Hello. Please help me to resolve my weird issue. I have 3 tables in my DB and these tables has the same meaning. Table Subscriber, SubscriberQueue, SubscriberArj, SubscriberMove. Column sets are almost identical. Now I am running app based on iBatis, but have to move to hibernate. So let me explain the idea I am trying to implement:
I should have ONE class Subscriber, but with virtual column subscriberType, this column is indicating the table I use to fetch records. In code I should have
List<Subscriber> list = subscriberDAO.findByPrimaryKey(primaryKey, subscriberType) so in this code I pass primarykey and subscribertype, so telling it from which table to select records with which id. This way I am selecting records in ibatis, in xml mapping of ibatis I use discriminator, which insert different fields sets depends on subscriber type, or extends existing fields set, property set is always the same, just columns aliases are different. So it seems that it pretty flexible. But I have read tons of docs of hibernate and cannot implement this idea. The concept is one table one class but why do I need 3 classes with identical structure just because they are represents different tables? Joins and subclasses are not desirable because it offers unnecessary select, I need select from ONE table specifies by column value, I dont need select * from table1 join ...
In other words, please help me to understand the best way of doing it in hibernate, I just explained how it worked for me before, may be hibernate solution will be much more graceful. So desirable:
1) One entity class
2) One mapping
3) "table-name" parameter, ability to choose from specific table, just one table, not join
4) Ability to set custom columns for the table (aka column alias)
Example from iBatis:
Code:
<resultMap id="myres" class="MyClass">
<resultProperty id="blabla" column="mycol1"/>
</resultMap>
<select id="myselect1" resultMap="myres">
<isEqual property="flag" value="table_1">
select column_1 as mycol1 from table_1
</isEqual>
<isEqual property="flag" value="table_2">
select column_2 as mycol1 from table_2
</isEqual>
</select>
Please help. Thanks in advance