Batch fetching doing N+1 Query when NamedQuery is called after a NativeQuery in JBoss EAP 7

Solution Verified - Updated -

Issue

Batch fetching doing N+1 Query when NamedQuery is called after a NativeQuery inside a transaction in the JBoss EAP 7

       List<MyEntity> myEntities = entityManager.createNamedQuery(MyEntity.FIND_ALL, MyEntity.class).getResultList();

        String sql = "select u.* from MyEntity u";
        Query nativeQuery = entityManager.createNativeQuery(sql);
         logger.info("############# Executing Native Query #####################");
         List<MyEntity> myEntityNativeQuery = nativeQuery.getResultList();

        //myEntity.myEntityTwo is configured with @BatchSize . 
        for(MyEntity entity : myEntities){
            entity.getMyEntityTwo().size();
        }

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content