zhangcs45088648 2013-04-08 17:11
浏览 193
已采纳

JPA关联问题

JPA的PO代码片段如下:

父类:
[code="java"]
@Entity
@Table(name = "message_t")
@Inheritance(strategy = InheritanceType.JOINED)
public class Message implements Serializable {
[/code]

子类:
[code="java"]
@Entity
@Table(name = "draw_message_t")
@PrimaryKeyJoinColumn(referencedColumnName = "iwoid", name = "message_oid")
public class DrawMessage extends Message implements Serializable {
[/code]

子类有多个,此处略。

在查询父类Message 时,生成的sql会自动关联子类
sql:
[code="java"]
Hibernate:
select
message0_.iwoid as iwoid2_,
message0_.broadcast_type as broadcast2_2_,
message0_.content as content2_,
message0_.create_time as create4_2_,
message0_.creator as creator2_,
message0_.invalid_time as invalid6_2_,
message0_.modifier as modifier2_,
message0_.modify_time as modify8_2_,
message0_.msg_time as msg9_2_,
message0_.msg_type as msg10_2_,
message0_.remark as remark2_,
message0_.sender_oid as sender12_2_,
message0_.status as status2_,
message0_.title as title2_,
message0_1_.channel_name as channel1_5_,
message0_1_.channel_oid as channel2_5_,
message0_2_.draw_issue as draw1_6_,
message0_2_.draw_time as draw2_6_,
message0_2_.game_type as game3_6_,
message0_3_.apply_status as apply1_7_,
message0_4_.earn_type as earn1_8_,
message0_4_.game_id as game2_8_,
message0_4_.game_name as game3_8_,
message0_4_.game_oid as game4_8_,
message0_5_.ranking_year as ranking1_9_,
message0_5_.week_of_year as week2_9_,
message0_6_.ranking_date as ranking1_10_,
case
when message0_1_.message_oid is not null then 1
when message0_2_.message_oid is not null then 2
when message0_3_.message_oid is not null then 3
when message0_4_.message_oid is not null then 4
when message0_5_.message_oid is not null then 5
when message0_6_.message_oid is not null then 6
when message0_.iwoid is not null then 0
end as clazz_
from
message_t message0_
left outer join
busi_dynamic_t message0_1_
on message0_.iwoid=message0_1_.message_oid
left outer join
draw_message_t message0_2_
on message0_.iwoid=message0_2_.message_oid
[/code]

如果不想关联,还是通过JPAQL该怎么做

  • 写回答

1条回答 默认 最新

  • Dead_Knight 2013-04-13 08:30
    关注

    @Inheritance(strategy = InheritanceType.JOINED)
    这个策略改掉为如下的注解:
    @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
    这两种方式各有优缺点。single-table查询效率高,浪费表空间

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac虚拟机安装Windows,Windows中用idea跑项目,报错process finished with exit code -1073741819(0xc0000005) 如何解决?
  • ¥15 关于python爬虫返回js数据结构的处理
  • ¥15 ubuntu所用stm32标准库开发烧录没反映
  • ¥15 运维工程师(在职人员回答)
  • ¥15 Kmeans的趋势分析有会的吗
  • ¥20 R语言单细胞测序 对seurat对象进行标准化时出现问题
  • ¥15 Anaconda navigator updateor一直更新
  • ¥15 请问如何在matlab里使用raven工具?
  • ¥100 关于ios手游充值到一定金额,再点充值提示公众号的问题。
  • ¥15 求一个stm32串口控制程序