-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using twice @ManyToOne annotation for the same target entity
PostPosted: Fri Dec 08, 2006 5:16 pm 
Newbie

Joined: Mon Nov 27, 2006 2:11 pm
Posts: 6
Hi, I am having problems using the annotation @ManyToOne twice for the same target entity from the same source class (both source and target have composite pk). I have an entity that can be ditributable usging two diferent distributors, but each distributor can be associated with a lot of these entities. So I model this situation with 2 @ManyToOne, being the one side the Distributor object. I use naif name of fields for the sake of simplicity: a, b, c, etc.

Distributor pk = a, b, c, d (also part of the source entity pk)

@Entity
...
public class Distributable {

@ManyToOne
@JoinColumns({@JoinColumn(name="a", referencedColumnName="a"), @JoinColumn(name="b", referencedColumnName="b"), @JoinColumn(name="c", referencedColumnName="c"), @JoinColumn(name="d1", referencedColumnName="d")})
public Distributor getDistributor1() {
return distributor1;
}

public void setDistributor1(Distributor distributor1) {
this.distributor1 = distributor1;
}

@ManyToOne
//@JoinColumn(insertable = false, updatable = false)
@JoinColumns({@JoinColumn(name="a", referencedColumnName="a"), @JoinColumn(name="b", referencedColumnName="b"), @JoinColumn(name="c", referencedColumnName="c"), @JoinColumn(name="d2", referencedColumnName="d")})
public Distributor getDistributor2() {
return distributor2;
}

public void setDistributor2(Distributor distributor2) {
this.distributor2 = distributor2;
}


Problems:

When trying to deploy the following error is reported:

1)
javax.persistence.PersistenceException: org.hibernate.MappingException: Repeated column in mapping for entity: foo.Distributable column: b (should be mapped with insert="false" update="false")

Don't understand why, but in any case I then uncomment the line with "insertable = false..." and then get another error:

2)
org.hibernate.AnnotationException: A Foreign key refering foo.Distributor from foo.Distributable has the wrong number of column. should be 4

I double check each entity of the relation and their pks and they all have the requested 4 fields (i.e. the target composite primary key number of fields)

********************************************************

The only way I could go on with development was to full comment one of the @ManyToOne relationships

Any sugestions?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 4:51 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you cannot have twice the same column inserteble and updatable, one of the @JoinColumn(name="a") (etc) has to be insertable=false updatable=false

Plus @JoinColumns and @JoinColumn on the same property is illegal

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 1:43 pm 
Newbie

Joined: Mon Nov 27, 2006 2:11 pm
Posts: 6
Ok, I found the way of doing what you mean placing "insertable = false, updatable = false" inside each @JoinColumn of one of the @JoinColumns (that was what was not clear to me).

i.e:

@JoinColumns({@JoinColumn(name="a", referencedColumnName="a", insertable = false, updatable = false), @JoinColumn(name="b", referencedColumnName="b", insertable = false, updatable = false), ...})

Thank you very much for your support,
Leonardo


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

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.