Thanks for your quick reply sdparsons. Good answer, but it has one problem:
Gender attribute is an
entity that persist into database, so the primary key of any of the explained entities is composed by
Gender + Integer (this is the real problem: a composite key with an entity as part of itself).
¿Perhaps an approach like this could work? (this doesn't work, but maybe I'm doing something wrong):
* In
Link :
Code:
@ManyToOne
@JoinTable(name = "link_figures",
joinColumns = { @JoinColumn(name = "link_fig_fig"),
@JoinColumn(name="link_fig_gend") },
inverseJoinColumns={@JoinColumn(name="link_fig_link"),
@JoinColumn(name="link_fig_gend") } )
private List<Figure> linkFigures;
The exact error:
Code:
A Foreign key refering es.udc.lbd.portal.model.researcher.tests.ResearcherLink from es.udc.lbd.portal.model.researcher.tests.ResearcherLink has the wrong number of column. should be 1
Maybe this problem is due to using an @EmbeddedId in wich the join columns are two, but I don't really know...
Any ideas?
P.D. : The SQL code of the "join table" is this:
Code:
DROP TABLE IF EXISTS link_figures CASCADE;
CREATE TABLE link_figures
(
link_fig_fig INT,
link_fig_link INT,
link_fig_gend INT,
CONSTRAINT PK_LINK_FIG PRIMARY KEY(link_fig_fig,link_fig_link, link_fig_gend),
CONSTRAINT FK_LINK_FIG_FIG FOREIGN KEY(link_fig_fig, link_fig_gend)
REFERENCES researcher_figure(rese_fig_id, rese_fig_gend),
CONSTRAINT FK_LINK_FIG_LINK FOREIGN KEY(link_fig_link, link_fig_gend)
REFERENCES researcher_link(rese_link_id, rese_link_gend),
CONSTRAINT FK_LINK_FIG_GEND FOREIGN KEY(link_fig_gend)
REFERENCES gender(gend_id)
);