private String getSpecificJoinFetchAnnotation ( ) { List < Relation > manyToManyRelations = relation . getToEntity ( ) . getManyToMany ( ) . getList ( ) ; // we have only on many-to-many ? No problem, move on if ( manyToManyRelations . size ( ) <= 1 ) { return null ; } // we have many many to many relations ? and one requires eager, then we need to set the fetchmode for ( Relation relation : manyToManyRelations ) { if ( relation . getFetchTypeGetter ( ) != null && relation . getFetchTypeGetter ( ) . getFetch ( ) != null && relation . getFetchTypeGetter ( ) . getFetch ( ) . isEager ( ) ) { addImport ( "org.hibernate.annotations.Fetch" ) ; addImport ( "org.hibernate.annotations.FetchMode" ) ; return "@Fetch(value = FetchMode.SUBSELECT)" ; } } // no eager requested, move on return null ; }
When you have multiple eager bags you need to specify how you want to make them eager .