如何将Where子句应用于辅助表
我有一个使用主表和 2 个关联表创建的实体。我使用 hibernate 注释加入了主从表。 这是代码。
@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")})
})
这很好用。我想指定一个应用于辅助表“Table2”的Where 注释。默认情况下,hibernate 注释“@Where”仅应用于目标表,此处为“Table1”。结果,我收到一个 SQL 错误,指出在“Table1”中找不到 where 子句中包含的列。
我是否需要添加任何特殊指令到 @Where 以使 hibernate 在辅助表 Table2 上添加 SQL where 子句?
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")})
})
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'.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想 @Where 和 @WhereJoinTable 就是你想要的
I guess @Where and @WhereJoinTable is what your want