我试图映射2个表之间的多对多的关系,两者都具有复合主键休眠@ManyToMany映射与复合键
LSFOCTB which primary key is composed of : LSFOC_CODSOC,LSFOC_CODLSC,LSFOC_CODFOC
LSFORTB which primary key is composed of : LSFOR_CODSOC,LSFOR_CODLSC,LSFOC_CODFOR
The table in charge of the ManyToMany relationship is :
LSFCFTB, with : LSFCF_CODSOC,LSFCF_CODLSC,LSFCF_CODFOC,LSFCF_CODFOR
因此,在休眠模型映射LSFOCTB,我想:
@ManyToMany(targetEntity = package.LSFOCTB.class, cascade = { CascadeType.PERSIST,
CascadeType.MERGE })
@JoinTable(name = "LSFCFTB", joinColumns = {
@JoinColumn(name = "LSFCF_CODLSC", referencedColumnName = "LSFOC_CODLSC"),
@JoinColumn(name = "LSFCF_CODFOC", referencedColumnName = "LSFOC_CODFOC"),
@JoinColumn(name = "LSFCF_CODSOC", referencedColumnName = "LSFOC_CODSOC") },
inverseJoinColumns = { @JoinColumn(name = "LSFCF_CODLSC", referencedColumnName = "LSFOR_CODLSC"),
@JoinColumn(name = "LSFCF_CODFOR", referencedColumnName = "LSFOR_CODFOR"),
@JoinColumn(name = "LSFCF_CODSOC", referencedColumnName = "LSFOR_CODSOC") })
之前的获得者。 但它不会工作... 错误,试图访问遥远的集合时是:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans-dao.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for collection: package.LSFOCTB.distantCollection column: LSFCF_CODLSC
是否已经成功地使一个多对多关系的Hibernate映射工作? 如果是这样,我的映射有什么问题? 谢谢你的帮助!
我一直在寻找关于以下页面的信息:http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html#entity-hibspec章节:2.2.5.3.3。多对多 还有: http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=003838 – 2008-10-13 14:03:21