Does anyone know the hibernate mapping file equivalent of the referencedColumnName property of a @JoinColumns annotation, something like this:
@ManyToOne
@JoinColumns ({
@JoinColumn(name="FIELD_0", referencedColumnName="A", insertable=false, updateable=false),
@JoinColumn(name="FIELD_1", referencedColumnName="B", insertable=false, updateable=false),
@JoinColumn(name="FIELD_2", referencedColumnName="C", insertable=false, updateable=false),
@JoinColumn(name="FIELD_3", referencedColumnName="D", insertable=false, updateable=false)
Moving to annotations is not an option and we need to setup a foreign key reference with a composite key where column names are different between tables.
Thanks in advance.
I've been working on this same problem. I saw your question before I solved it, figured I would come back here and help you. I'm using 4.2.2.
I genericized the names, but I think you will get the point. The "parent" class contains the collection of "child" objects, which means the "child" table has a foreign key constraint to the "parent" table.
Pay close attention to the following: 1. The order of the columns in the collection keys must match the order in the composite-id. 2. The attributes on the bag collection are really important. What I have below is working for me.
Also, don't try to do anything with the association in either the "child" class or its mapping config. Just map the non-FK properties and let hibernate take care of the FKs.