我正在使用 spring 3.1、hibernate 4.0.1.FINAL 和 spring-data-jpa 1.0.2.RELEASE。所以假设我有一个many-to-many
betweenclass A
并且class B
我映射为ABMap
. 我还有另一个多对多之间的class C
映射class D
为CDMap
. 我有一个ABMapID
带有 @Embeddable 注释的类
@Embeddable
public class ABMapID{
private String aID;
private String bID;
}
//... setters and getters
所以映射本身在下面
@Entity
public class ABMap {
@Id
@AttributeOverrides({
@AttributeOverride(name = "aID", column = @Column(name = "a_id",insertable = false, updatable = false)),
@AttributeOverride(name = "bID", column = @Column(name = "b_id", insertable = false,updatable = false))
})
private ABMapID ID;
@ManyToOne(targetEntity = A.class)
@JoinColumn(name = "a_id",insertable = false,updatable = false)
private A a;
@ManyToOne(targetEntity = B.class)
@JoinColumn(name = "b_id", insertable = false, updatable = false)
private B b;
//.... setters and getters
}
现在假设我们要更改ABMap
由ACDMap
aIDACDMapID
和 CDMapID(它本身由 cID、dID 组成)组成的位置。所以我的新关联 ID 是 ACDMapID
@Embeddable
public class ACDMapID {
private String aID;
private CDMapID cdmapID;
}
and the entity is mapped like so
@Entity
public class ACDMap {
@Id
@AttributeOverrides({
@AttributeOverride(name = "aID", column = @Column(name = "a_id",insertable = false, updatable = false)),
@AttributeOverride(name = "cdmapID", column = @Column(name = "dcmap_id", insertable = false,updatable = false))
})
private ACDMapID ID;
}
所以运行这个给我这个错误
原因:org.hibernate.AnnotationException:从 ACDMap 引用 CDMap 的外键具有错误的列数。应该是 2
有没有办法进行映射?更可取的是,我想保持 CDMap 原样。