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

Posted 涤新云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn报错相关的知识,希望对你有一定的参考价值。

 

自己的项目没有测通  可能是自己项目原因——因为自己项目中级联关系的类涉及太多 

自己的项目【这样的配置报错】

@OneToMany(fetch=FetchType.LAZY,cascade = { CascadeType.REMOVE }, mappedBy="scProjectTecApply")
@JoinColumn(name="busid")
public List<ScTeam> getTeams() {
return teams;
}

【修改后配置】

@OneToMany(fetch=FetchType.LAZY,cascade = { CascadeType.REMOVE }, mappedBy="scProjectTecApply")
public List<ScTeam> getTeams() {
return teams;
=======================报错

could not initialize a collection:

[com.jspxcms.core.domain.ScProjectTecApply.teams#2098];

SQL [select teams0_.scProjectTecApply as scProjec6_77_1_, teams0_.id as id1_, teams0_.id as id80_0_, teams0_.busid as busid80_0_, teams0_.deptname as deptname80_0_, teams0_.leader as leader80_0_, teams0_.points as points80_0_, teams0_.scProjectTecApply as scProjec6_80_0_, teams0_.uname as uname80_0_, teams0_.weight_sort as weight8_80_0_ from sc_team teams0_ where teams0_.scProjectTecApply=?];

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘teams0_.scProjectTecApply‘ in ‘field list‘

 

=============

【修改为这样】仍然报错

@OneToMany(fetch=FetchType.LAZY,cascade = { CascadeType.REMOVE })
@JoinColumn(name="busid")
public List<ScTeam> getTeams() {
return teams;
}

 

could not initialize a collection:

[com.jspxcms.core.domain.ScProjectTecApply.teams#2098];

SQL [select teams0_.busid as busid77_1_, teams0_.id as id1_, teams0_.id as id80_0_, teams0_.busid as busid80_0_, teams0_.deptname as deptname80_0_, teams0_.leader as leader80_0_, teams0_.points as points80_0_, teams0_.scProjectTecApply as scProjec6_80_0_, teams0_.uname as uname80_0_, teams0_.weight_sort as weight8_80_0_ from sc_team teams0_ where teams0_.busid=?]; 
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘teams0_.scProjectTecApply‘ in ‘field list‘

 

 

=====================

【网上资料】

异常:Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn
错误发生在下面这些代码中
@OneToMany(mappedBy="parent",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
@JoinColumn(name="parent_id")
private List<Category> child = new ArrayList<Category>();
后来发现在3.5.3版本中@JoinColumn与mappingBy是互斥的,之前在hibernate.3.3.2中都是正确无误的,也就是hibernate.3.3.2允许这两个互相存在。
所以,如果升级到hibernate3.5.3想测试成功的话,mappBy="parent",就应该去掉,正确的配置应该是这样
@OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
@JoinColumn(name="parent_id")
private List<Category> child = new ArrayList<Category>();

以上是关于Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn报错的主要内容,如果未能解决你的问题,请参考以下文章

SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable

Not registered via @EnableConfigurationProperties or marked as Spring component

Idea中modules mark as不显示sources/tests等(只显示excluded)问题

Build step ‘Execute shell‘ marked build as failure

destoon修复Table xxx is marked as crashed and should

Idea Mark Directory as 下的文件夹分别代表的含义