0

I know this issue was asking in many site but they only give the solution for single entity with multiple list(child). I'm using spring jpa with entity with multi level of 1 to many relationship (nested oneToMany).

like below Module-> sub module -> function

1 module have many submodule, and submodule hava many function. I can't use Set as I need ordering in each layer, except changing to SortedSet, what other solution if I need to use List?

I saw many solution, example was just single layer https://stackoverflow.com/a/51055523/6452685 https://vladmihalcea.com/spring-data-jpa-multiplebagfetchexception/

Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags: [entity.ScModule.scSubModules, entity.ScSubModule.scFunctions]
        at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:76) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.loader.hql.QueryLoader.<init>(QueryLoader.java:110) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.createQueryLoader(QueryTranslatorImpl.java:249) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:213) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:636) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:748) ~[hibernate-core-5.6.12.Final.jar:5.6.12.Final]
        ... 78 common frames omitted

I try use @OrderColumn in 1 of the layer which MultipleBagFetchException is not throw but the result return contain many null value in that layer

{
    "id": "fba21ad3-0fbe-48de-a351-c0a9bfbd2261",
    "name": "General Settings",
    "enabled": true,
    "ordered": 200,
    "scSubModules": [
      null,
      null,
      null,
      null,
      null,
      null,
      null,
zack
  • 9
  • 1
  • 6

0 Answers0