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: Same column used in multiple associations problem?
PostPosted: Wed Apr 01, 2009 6:11 pm 
Newbie

Joined: Mon Apr 14, 2008 1:13 pm
Posts: 11
I'm creating a sports related schema and have 3 entities: Sport, Team and Player.

The DB primary key for for sport is sport_id while both Team and Player have composite primary keys consisting of sport_id (a foreign key to Sport obviously) and team_id or player_id.

Sport and Team are fine but I'm running into an issue with Player which has foreign keys to BOTH Sport and Team.... seems trivial but I can't find an answer on the forums

@Entity
public class Sport {
@Id
private int sportId;

...
}

@Entity
public class Team {
@Id
@ManyToOne
@JoinColumn(name="sport_id")
private Sport sport;

@Id
private int teamId;

...
}

@Entity
public class Player {
@Id
@ManyToOne
@JoinColumn(name="sport_id")
private Sport sport;

@Id
private int playerId;

// not part of ID / pkey
// hibernate NO LIKEY this relationshi
@ManyToOne
@JoinColumns({
@JoinColumn(name="sport_id"),
@JoinColumn(name="team_id)
})
private Team team;

...
}

the ManyToOne from Player to Team yields this error however:
A Foreign key refering com.espn.composer.contentlink.entity.Team from com.espn.composer.contentlink.entity.Player has the wrong number of column. should be 1

See the full trace below... what am doing wrong? This seems like it should be pretty easy :-)


Hibernate version: 3.2.6

Mapping documents: n/a

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs: Caused by: javax.persistence.PersistenceException: org.hibernate.AnnotationException: A Foreign key refering com.espn.composer.contentlink.entity.Team from com.espn.composer.contentlink.entity.Player has the wrong number of column. should be 1
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:247)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at com.espn.composer.contentlink.test.PlayerTest.<clinit>(PlayerTest.java:12)
Caused by: org.hibernate.AnnotationException: A Foreign key refering com.espn.composer.contentlink.entity.Team from com.espn.composer.contentlink.entity.Player has the wrong number of column. should be 1
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:255)
at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:64)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:178)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:235)
... 4 more


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.