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

今天在写Hibernate 实体映射的注解的时候:发现了这个错误 

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

错误代码:

@OneToMany(cascade = CascadeType.ALL,mappedBy = "depart")
@JoinColumn(name="depid")
public Set<EmpvoVo> getEmps(){
        return emps;
}

通过查询网上资料发现:在Hibernate4.0的版本中,mappedBy和@JoinColumn 是互斥的。在4.0的版本是不允许这两个共同出现。

            但是又为了让它们关联,我们可以只写 mappedBy。它包含了JoinColumn 的功能,所以也就可以不用指定外键列了。

正确代码就是把 @JoinColumn(name="depid") 去掉

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

上一篇:Netflix Eureka本地简单实现分布式开发


下一篇:Invalid bound statement (not found): mybatis.mapper.UserMapper.findUserById