-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Select from different tables depends on column
PostPosted: Thu Mar 28, 2013 10:07 am 
Newbie

Joined: Thu Mar 28, 2013 9:50 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.