The two table structures are as follows Table_a:id, COLA1, COLA2
Table_b:id, a_id, COLB1, COLB2
A and B are a one-to-many relationship. I set up the following relationship through Anotation on the B bean. @ManyToOne (cascade = Cascadetype.refresh, targetentity = table_a.class) @JoinColumn (name = "A_ID", referencedcolumnname = "ID", nullable = True, Insertable = false, updatable = False)
Now the problem comes, is in table_b.a_id = table_a.id at the same time, also request Table_b.colb1= "ABC".
The solution is as follows:
@ManyToOne (cascade = Cascadetype.refresh, targetentity = Table_a.class)
@JoinColumnsOrFormulas (value={
@JoinColumnOrFormula (column= @JoinColumn (name = "A_ID", referencedcolumnname = "ID", nullable = True, Insertable =false, updatable = False), @JoinColumnOrFormula (formula= @JoinFormula (value= "ABC", referencedcolumnname = "COLB1"))
})
The emphasis is on the use of @joinformula (similar to @joincolumn):
Value indicates the values of the corresponding column (you can also write an SQL expression here),
Referencedcolumnname indicates the name of the column
Because there are more than one association relationship, you need to include multiple criteria by using labels such as @joincolumnsorformulas, @JoinColumns, @JoinrFormulas.
Reference: http://www.oschina.net/question/54953_45536