Hi, i've read several posts for 3 days but i can find a solution to my case.
I have this mapping :
@Entity @DynamicInsert @DynamicUpdate @Table(name = "CUSTOMER") public class Customer{
private CustomertSubFamilly clntClsfCode private CustomerFamilly clntClfaCode;
@ManyToOne(fetch = FetchType.LAZY) @JoinColumns({ @JoinColumn( name = "CLNT_CLFA_CODE", referencedColumnName = "CLSF_CLFA_CODE"), @JoinColumn(name = "CLNT_CLSF_CODE", referencedColumnName = "CLSF_CODE") }) public CustomerSubFamilly getClntClsfCode() { return this.clntClsfCode; }
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CLNT_CLFA_CODE", insertable = false, updatable = false) public CustomerFamilly getClntClfaCode() { return this.clntClfaCode; } } ClientSubFamily class has an EmbeddedId wich is an Embeddable class with two fields CLSF_CLFA_CODE and CLSF_CODE.
I used hibernate tools reverse engineering to create this.
Here i want to insert a new CUSTOMER and be abble to set in this CUSTOMER a CustomerFamilly and a CustomerSubFamilly on the same insert statement.
The problem is that the column CLNT_CLFA_CODE is mapped twice in the same class wich is not allow by hibernate. I've read several topics on this but i still don't understand why i can do this because the first mapping of CLNT_CLFA_CODE is in a multiple columns mapping.
I understand why i can not define the same column in several mapping (@JoinColum) in the same class when this column is single mapped but not when it is a part of multiple mapping (@JoinColumnS). Why hibernate consider that this is a repeated column despite it is defined in a multiple columns mapping (JoinColumS) ?
Why does hibernate not consider that it is the two columns (JoinColumns) which are one mapping ? and not each of the JoinColumn in JoinColumnS.
And is there a way to insert both CustomerFamilly and CustomeSubFammily when inserting Customer (or update Customer) ?
Note: i know this is not a good database relationship shema but they me let no choice, i have to deal with it.
Thanks in advance.
|