@JoinColumn matching multiple fields

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.