zoukankan      html  css  js  c++  java
  • jpa 报错: Unable to build Hibernate SessionFactory; nested exception is org.hibernate.loader.MultipleBagFetch

    model代码如下:

    @OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL)
        @Where(clause="isValid=1 and orderType=1")
        @JoinColumn(name = "orderUUID", referencedColumnName = "JobShippingOrderUUID",insertable = false, updatable = false)
        public List<BoJobgoods> getBoJobgoodsList() {
            return boJobgoodsList;
        }
    
        @OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL)
        @Where(clause="isValid=1 and orderType=1")
        @JoinColumn(name = "orderUUID", referencedColumnName = "JobShippingOrderUUID",insertable = false, updatable = false)
        public List<BoJobcontainer> getBoJobcontainerList() {
            return boJobcontainerList;
        }

    启动就报错 Unable to build Hibernate SessionFactory; nested exception is org.hibernate.loader.MultipleBagFetch。。。。。。。。。。

    原因是同一个model里不能有二个 FetchType.EAGER 

    于是把另一个改成:FetchType.LAZY 再次启动成功

    但是访问接口又报另一个错:

    Could not write JSON: failed to lazily initialize a collection of role: com.kintech.model.domain.bo.BoJobshippingorder.boJobgoodsList, could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: 

    于是再改把后码的list字段添加@Fetch(FetchMode.SUBSELECT)注解代码如下:

    @OneToMany(fetch=FetchType.EAGER)
        @Where(clause="isValid=1 and orderType=1")
        @JoinColumn(name = "orderUUID", referencedColumnName = "JobShippingOrderUUID",insertable = false, updatable = false)
        public List<BoJobgoods> getBoJobgoodsList() {
            return boJobgoodsList;
        }
    
        public void setBoJobgoodsList(List<BoJobgoods> boJobgoodsList) {
            this.boJobgoodsList = boJobgoodsList;
        }
    
        @OneToMany(fetch=FetchType.EAGER)
        @Fetch(FetchMode.SUBSELECT)
        @Where(clause="isValid=1 and orderType=1")
        @JoinColumn(name = "orderUUID", referencedColumnName = "JobShippingOrderUUID",insertable = false, updatable = false)
        public List<BoJobcontainer> getBoJobcontainerList() {
            return boJobcontainerList;
        }

     再运行,完全搞定



    欢迎加入JAVA技术交流QQ群:179945282

    欢迎加入ASP.NET(C#)交流QQ群:17534377


  • 相关阅读:
    uva 11294 Wedding
    uvalive 4452 The Ministers’ Major Mess
    uvalive 3211 Now Or Later
    uvalive 3713 Astronauts
    uvalive 4288 Cat Vs. Dog
    uvalive 3276 The Great Wall Game
    uva 1411 Ants
    uva 11383 Golden Tiger Claw
    uva 11419 SAM I AM
    uvalive 3415 Guardian Of Decency
  • 原文地址:https://www.cnblogs.com/q149072205/p/14819175.html
Copyright © 2011-2022 走看看