论坛首页 Java企业应用论坛

joined-subclass中的一个疑问?

浏览 1982 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-11-26  
joined-subclass中的一个疑问?

假设有父类Card  ,子类 Card_1,Card_2,Card_3
Code:为
[/list]
public class Card {
private Long id;
private String card_name;
//get/set方法省略
}

public class Card_1 extends Card {
private String card_1_filed;//get/set方法省略
}

public class Card_2 extends Card {
private String card_2_filed;//get/set方法省略
}

public class Card_3 extends Card {
private String card_3_filed;//get/set方法省略
}

metadata mapping file :

<hibernate-mapping package="hibernate.model" auto-import="false">
<class name="Card" table="superCard_join_2">
<id name="id" column="card_id">
<generator class="native" />
</id>
<discriminator column="card_type" type="string"></discriminator>
<property name="card_name" column="card_name" type="string" />

<subclass name="Card_1" discriminator-value="1">
<join table="Card_1_2" fetch="select">
<key column="card_id"></key>
<property name="card_1_filed" type="string"></property>
</join>
</subclass>

<subclass name="Card_2" discriminator-value="2">
<join table="Card_2_2" fetch="select">
<key column="card_id"></key>
<property name="card_2_filed" type="string"></property>
</join>
</subclass>

<subclass name="Card_3" discriminator-value="3">
<join table="Card_3_2" fetch="select">
<key column="card_id"></key>
<property name="card_3_filed" type="string"></property>
</join>
</subclass>

</class>
</hibernate-mapping>
[list=]

我做父类查询的时候生成的sql语句为:
select
        card0_.card_id as card1_0_,
        card0_.card_name as card2_0_,
        card0_1_.card_1_filed as card2_1_,
        card0_2_.card_2_filed as card2_2_,
        card0_3_.card_3_filed as card2_3_,
        case
            when card0_1_.card_id is not null then 1
            when card0_2_.card_id is not null then 2
            when card0_3_.card_id is not null then 3
            when card0_.card_id is not null then 0
        end as clazz_
    from
        superCard_join card0_
    left outer join
        Card_1 card0_1_
            on card0_.card_id=card0_1_.card_id
    left outer join
        Card_2 card0_2_
            on card0_.card_id=card0_2_.card_id
    left outer join
        Card_3 card0_3_
            on card0_.card_id=card0_3_.card_id

请问各位用什么方式才能将子类的left out join去掉呢?
论坛首页 Java企业应用版

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