Dear,
I have a problem with hibernate for making mapping objet many to many with an intermediate table which only have foreign key.
I have in SQL 3 tables:
element( idElement: primary, date: primary, ...)
recherche( idRecherche: primary, ... )
conceptrecherche( idElement: primary and foreign key to element, idrecherche: primary and foreign key to recherche)
I want for one element of Recherche to get all elements (element of the class Element) (thank to conceptrecherche intermediate table with foreign key)
In this way I do something like:
Code:
@Entity
@Table(name = "recherche")
public class Recherche implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "idRecherche")
@JoinTable(name = "conceptrecherche", joinColumns = {@JoinColumn(name = "idRecherche", referencedColumnName = "idRecherche")}, inverseJoinColumns = {@JoinColumn(name = "idElement", referencedColumnName = "idElement")})
@ManyToMany
private List<Element> elementCollection;
...
}
@Entity
@Table(name = "element")
public class Element implements Serializable {
@EmbeddedId
protected ElementPK elementPK;
@JoinColumn(name = "idElement", referencedColumnName = "idElement")
@ManyToMany
private List<Recherche> rechercheCollection;
..
}
and the primary key for element:
@Embeddable
public class ElementPK implements Serializable {
@Basic(optional = false)
@Column(name = "idElement")
private int idElement;
@Basic(optional = false)
@Column(name = "histDate")
@Temporal(TemporalType.TIMESTAMP)
private Date histDate;
...
}
But when I tried it, I have an error:
Code:
org.hibernate.AnnotationException: referencedColumnNames(idElement) of IK.Db.Entities.Recherche.elementCollection referencing IK.Db.Entities.Element not mapped to a single property
Thank a lot for your help!
Fabien