http://www.oschina.net/question/54953_45536
@JoinColumn Question Justforfly on 3-23 15:48 2 months ago, 1 back/281 read, finally replied: 2 months ago (0 people to collect this topic, I want to collect | report) Discussion Area» Technical FAQ Top 0 Tread two sheet structure 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".
I would like to ask you how this situation is handled. How to use @joincolumn. Tags: Hibernate I want to ask the same question a total of 0 people want to ask the same question to add a topic Note» A total of 1 additional instructions justforfly: In Hibernate this aspect, who is more experienced, hope to guide twos. can only use SQL to solve this problem. 2 months ago by rating | Show the latest answer | Back to the top of the page there are 1 answers I want to answer» justforfly answer in 2012-03-31 11:12 (2 months ago) report
I finally solve the problem, share the code, hope can also help others.
1 |
@ManyToOne (cascade = Cascadetype.refresh, targetentity = table_a.class) |
2 |
@JoinColumnsOrFormulas (value={@JoinColumnOrFormula (column= @JoinC Olumn (name = "A_ID", referencedcolumnname = "ID", nullable = True, Insertable = false, updatable = False)) |
3 |
&nbs P;        &NBSP, @JoinColumnOrFormula (formula= @JoinFormula (value= "") ABC ' ", referencedcolumnname =" COLB1 ")) |
4 |
      &NBSP}) |
The emphasis is on @joinformula use (similar to @joincolumn):
Value indicates the value of the corresponding column (the SQL expression can also be written here), and the
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. Helpful (0) | No Help (0) | Comments (0) | Reference to this answer