zoukankan      html  css  js  c++  java
  • 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>();

  • 相关阅读:
    重构29-Remove Middle Man(去掉中间人)
    重构30-Return ASAP(尽快返回)
    重构26-Remove Double Negative(去掉双重否定)
    yaml语法学习3
    运行原理探究2
    SpringBoot简介 1
    SpringMVC项目所引用的一切依赖jar包和自定义设置
    2020/07/03 初始mybatis
    json数据格式字符串在java中的转移
    项目中遇到的一些异常
  • 原文地址:https://www.cnblogs.com/dixinyunpan/p/5999709.html
Copyright © 2011-2022 走看看