java.lang.IllegalArgumentException: Expecting collection type [java.lang.Object] after upgrading Hibernate-core to 5.6

63 Views Asked by At

after upgrading hibernate from 5.0.2 to 5.6.15 and spring from 5.3.22 to 5.3.31 got this error:

weblogic.application.ModuleException: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags: [multiElementEditorDefinitionsList, structure]
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        Truncated. see log file for complete stacktrace
Caused By: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags: [multiElementEditorDefinitionsList, structure]
        at org.hibernate.loader.plan.exec.internal.AbstractLoadQueryDetails.generate(AbstractLoadQueryDetails.java:193)
        at org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails.<init>(EntityLoadQueryDetails.java:85)
        at org.hibernate.loader.plan.exec.internal.BatchingLoadQueryDetailsFactory.makeEntityLoadQueryDetails(BatchingLoadQueryDetailsFactory.java:64)
        at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.<init>(AbstractLoadPlanBasedEntityLoader.java:97)
        at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.<init>(AbstractLoadPlanBasedEntityLoader.java:112)
        Truncated. see log file for complete stacktrace

solved By changing the fetch to select instead of join at this part on one of the hbm.xml files:

<bag name="multiElementEditorDefinitionsList" cascade="persist,merge,save-update,delete-orphan" lazy="false" fetch="select" inverse="true">
    <key column="TEMPLATE_ID" on-delete="cascade"/>
    <one-to-many class="MultiElementEditorDefinitions"/>
</bag>

then I got this Error:

Caused By: java.lang.IllegalArgumentException: Expecting collection type [java.lang.Object]
    at org.hibernate.metamodel.internal.AttributeFactory.determineCollectionType(AttributeFactory.java:982)
    at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:827)
    at org.hibernate.metamodel.internal.AttributeFactory$PluralAttributeMetadataImpl.<init>(AttributeFactory.java:808)
    at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:587)
    at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:92)
    at org.hibernate.metamodel.internal.AttributeFactory.determineSimpleType(AttributeFactory.java:283)
    at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:100)
    at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:263)
    at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:275)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:319)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:471)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:728)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:746)
    at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:616)

at this subclass, especially the m_basedOnItems component:

<subclass name="ReferenceBusinessField" discriminator-value="3">
   <join table="BIS_REFERENCE_FIELD">
       <key column="ID" on-delete="cascade"/>
       <component name="m_defaultValue" class="{class1}" access="field">
           <component name="value" class="{class2}">
               <property name="externalId" type="string" column="DEFAULT_VALUE" length="255"/>
           </component>
           <property name="overridden" column="DEFAULT_VALUE_OVERRIDDEN" type="boolean"/>
       </component>
       <component name="m_basedOnItems" class="{class1}" access="field">
           <bag name="value" table="BIS_REF_FIELD_SUBTYPE" lazy="false" fetch="select" cascade="all">
               <key column="FIELD_ID"/>
               <element column="BASED_ON_ITEM_ID" type="{class3}"/>
           </bag>
       </component>
   </join>
   <subclass name="ReferenceBusinessEntityField" discriminator-value="4"/>
</subclass>

what I tried: I added all compile dependencies and tried to change the bag to set/list/map still getting same error I also tried to change <element> to one-to-many ... tried to use <composite-element> inside the bag also tried adding this component but led to another error related to db: <property name="overridden" column="BASED_ON_ITEM_OVERRIDDEN" type="boolean"/>

but nothing helped!

please Advice!

0

There are 0 best solutions below