-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Repeated column in mapping for entity with composite keys
PostPosted: Wed Oct 15, 2014 9:10 am 
Newbie

Joined: Wed Oct 15, 2014 8:35 am
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.