如何申请Where子句中辅助表 [英] How to apply Where clause to secondary table

查看:183
本文介绍了如何申请Where子句中辅助表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体,一个主表和2相关联表创建。我加入了使用Hibernate标注主副表。
这里是code。

I have an Entity created with a main table and 2 associated tables. I joined the primary-secondary tables using the hibernate annotations. Here is the code.

@Entity
@Table(name = "Table1")
@org.hibernate.annotations.Entity(dynamicUpdate=true)
@org.hibernate.annotations.Tables ( {
    @org.hibernate.annotations.Table(appliesTo = "Table2", optional = false ),
    @org.hibernate.annotations.Table(appliesTo = "Table3", optional = false )
})
//@org.hibernate.annotations.Table(appliesTo = "Table2", optional = false )
@PrimaryKeyJoinColumn(name="t1_column1")
@SecondaryTables({
    @SecondaryTable(name = "Table2", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "t2_col1", referencedColumnName = "t1_col1")}  ),
    @SecondaryTable(name = "Table3", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "t3_col1", referencedColumnName = "t1_col1")})
})

这工作正常。我想指定在哪里注释,将适用于辅助表表2。默认情况下,休眠注释@Where被应用到只有目标表,这里是表1。其结果是,我得到一个SQL错误,包括在where子句中没有表1中的列。

This works fine. I want to specify a Where annotation that will apply to the secondary table 'Table2'. By default the hibernate annotation "@Where" gets applied to only the target table which here is 'Table1'. As a result, I get an SQL error that the column included in the where clause is not found in 'Table1'.

时有什么特别的指令,我需要添加到@Where使休眠添加SQL,其中在二次表条文表2?

Is there any special directive that I need to add to the @Where to make hibernate add the SQL where clause on the secondary table Table2?

推荐答案

我猜@Where和@WhereJoinTable是你想要

I guess @Where and @WhereJoinTable is what your want

这篇关于如何申请Where子句中辅助表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆