4 Replies Latest reply on Nov 17, 2006 1:29 PM by Juergen Zimmermann

    2 FETCH Joins in 1 query

    Juergen Zimmermann Master

      I'm using JBoss 4.0.5GA with EJB3 annotations. I want to read objects of class Customer and also fetch their orders plus the shipments of these orders. I tried this named query:

      SELECT DISTINCT c
      FROM Customer c
       LEFT JOIN FETCH c.orders o
       LEFT JOIN FETCH o.shipments
      WHERE c.lastname = :lastname
      


      However, I get the following exception:
      org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
       at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)
       at org.hibernate.loader.hql.QueryLoader.<init>(QueryLoader.java:101)
       at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:181)
       at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
       at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
       at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
       at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
       at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:400)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:351)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:688)


      What's going wrong? Any hint is appreciated!