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>();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM