How to apply Where clause to secondary table
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 err开发者_Python百科or 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?
I guess @Where and @WhereJoinTable is what your want
精彩评论