首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Hibernate错误(1):Associations marked as 地图pedBy must not define database 地图pings

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

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;

@OneToMany(fetch = FetchType.LAZY)

@JoinColumn(name = "dept_id")

public List<User> getUser() {

? ? return user;

}

public void setUser(List<User> user) {

? ? this.user = user;

}

?

热点排行