日期:2014-05-16  浏览次数:20659 次

Hibernate异常(1):Associations marked as mappedBy must not define database mappings

异常:Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn

hibernate升级到3.5版本或者更新的版本时出现这样的异常,举个例子:

?

private List<User> user;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "dept")

@JoinColumn(name = "dept_id")

public List<User> getUser() {

? ? return user;

}

public void setUser(List<User> user) {

? ? this.user = user;

}

?

在3.5版本之后@JoinColumn与mappingBy是互斥的,而在更早版本的hibernate是允许这两个互相存在。所以升级到hibernate3.5之后,mappBy="dept",就应该去掉,正确的写法如下:

private List<User> user;

@OneToMan