<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 
        <base href="https://hibernate.atlassian.net"> 
        <title>Message Title</title> 
    </head> 
    <body class="jira" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429"> 
        <table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0" bgcolor="#f5f5f5"> 
            <!-- header here --> 
            <tbody>
                <tr> 
                    <td id="header-pattern-container" style="padding: 0; border-collapse: collapse; padding: 10px 20px"> 
                        <table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="header-avatar-image-container" valign="top" style="padding: 0; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px" width="32"> <img id="header-avatar-image" class="image_fix" src="https://avatar-cdn.atlassian.com/ec5c1e0d4b187411bb37b88003072ade?s=48&amp;d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fec5c1e0d4b187411bb37b88003072ade%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top"> </td> 
                                    <td id="header-text-container" valign="middle" style="padding: 0; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="antonio.benvenuto" id="email_antonio.benvenuto" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=antonio.benvenuto" style="color:#6c797f;; color: #3b73af; text-decoration: none">Antonio</a> <strong>updated</strong> an issue </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="email-content-container" style="padding: 0; border-collapse: collapse; padding: 0 20px"> 
                        <table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; border-spacing: 0; border-collapse: separate"> 
                            <tbody>
                                <tr> 
                                    <!-- there needs to be content in the cell for it to render in some clients --> 
                                    <td class="email-content-rounded-top mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 15px; background-color: #ffffff; border-left: 1px solid #cccccc; border-top: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly" height="10" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> 
                                        <table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="page-title-pattern-first-line " style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; padding-top: 10px"> <a href="https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMzNiNjRhYTU0ZDdmNGZiNGI0YmJmOTNkYzI0ZGQ4MDkiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none">Hibernate ORM</a> / <a href="https://hibernate.atlassian.net/browse/HHH-13203?atlOrigin=eyJpIjoiMzNiNjRhYTU0ZDdmNGZiNGI0YmJmOTNkYzI0ZGQ4MDkiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-2866f2e4-37aa-4ecf-bbd7-d6c8cab792b5" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom"></a> <a href="https://hibernate.atlassian.net/browse/HHH-13203?atlOrigin=eyJpIjoiMzNiNjRhYTU0ZDdmNGZiNGI0YmJmOTNkYzI0ZGQ4MDkiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none">HHH-13203</a> </td> 
                                                </tr> 
                                                <tr> 
                                                    <td style="vertical-align: top;; padding: 0; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-13203?atlOrigin=eyJpIjoiMzNiNjRhYTU0ZDdmNGZiNGI0YmJmOTNkYzI0ZGQ4MDkiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none">Fetchs used into criteria query seems to be ignored when bytecode enhancement is enabled</a> </span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  wrapper-special-margin" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 10px; padding-bottom: 5px" bgcolor="#ffffff"> 
                                        <table class="keyvalue-table" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Change By:</th> 
                                                    <td style="padding: 0; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top"> <a class="user-hover" rel="antonio.benvenuto" id="email_antonio.benvenuto" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=antonio.benvenuto" style="color:#6c797f;; color: #3b73af; text-decoration: none">Antonio</a> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand  issue-description-container" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 5px; padding-bottom: 10px" bgcolor="#ffffff"> 
                                        <table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0; border-collapse: collapse; padding: 0 0 10px"> <span class="diffcontext">I have an Entity A which contains a @OneToOne relation to the Entity B and Entity C. Entity B and Entity C have, in turn, a @OneToOne relation to Entity B1 and Entity C1:<br><br><br>{code:java}<br>A<br> | <br> |--B&nbsp;&nbsp;@OneToOne<br>&nbsp;&nbsp;&nbsp;&nbsp;|<br>&nbsp;&nbsp;&nbsp;&nbsp;|--B1&nbsp;&nbsp;&nbsp;@OneToOne<br> |--C<br>&nbsp;&nbsp;&nbsp;&nbsp;|<br>&nbsp;&nbsp;&nbsp;&nbsp;|--C1&nbsp;&nbsp;&nbsp;@OneToOne<br><br>{code}<br><br>I need to select all data of Entity A with some fields of Entity B and Entity C. Fields of Entity B1 and C1 have to be ignored.<br><br><br>{code:java}<br>// The 'A' Entity (that I want to load with criteria)<br>@Entity<br>@Table(name = "users", schema = "test_db")&nbsp;&nbsp;&nbsp;<br>public class UserEntity<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;@Id<br>&nbsp;&nbsp;&nbsp;&nbsp;@GeneratedValue(strategy= GenerationType.IDENTITY)<br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "USER_ID")<br>&nbsp;&nbsp;&nbsp;&nbsp;private Integer userId;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "NAME")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String name;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "SURNAME")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String surname;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "EMAIL")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String email;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;// The B Entity Relation (wished)<br>&nbsp;&nbsp;&nbsp;&nbsp;@OneToOne(fetch = FetchType.LAZY)<br>&nbsp;&nbsp;&nbsp;&nbsp;@JoinColumn(name = "BADGE_ID")<br>&nbsp;&nbsp;&nbsp;&nbsp;private BadgeEntity badge;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;// The C Entity Relation (wished)<br>&nbsp;&nbsp;&nbsp;&nbsp;@OneToOne(fetch = FetchType.LAZY)<br>&nbsp;&nbsp;&nbsp;&nbsp;@JoinColumn(name = "ADDRESS_ID")<br>&nbsp;&nbsp;&nbsp;&nbsp;private AddressEntity address;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;// Getters and Setters<br>}<br><br>// The B Entity (relation that I eventually want to load fetching LEFT on father) <br>@Entity<br>@Table(name = "badges", schema = "test_db")<br>public class BadgeEntity<br>{&nbsp;&nbsp;&nbsp;&nbsp;<br><br>&nbsp;&nbsp;&nbsp;@Id<br>&nbsp;&nbsp;&nbsp;@GeneratedValue(strategy= GenerationType.IDENTITY)<br>&nbsp;&nbsp;&nbsp;@Column(name = "BADGE_ID", nullable = false)<br>&nbsp;&nbsp;&nbsp;private Integer badgeId;<br><br>&nbsp;&nbsp;&nbsp;@Column(name = "CODE", nullable = false, length = 10)<br>&nbsp;&nbsp;&nbsp;private String code;<br><br>&nbsp;&nbsp;&nbsp;@Column(name = "DESCRIPTION", nullable = false, length = 255)<br>&nbsp;&nbsp;&nbsp;private String description;<br><br>&nbsp;&nbsp;&nbsp;// The B1 Entity Relation (not wished)<br>&nbsp;&nbsp;&nbsp;@OneToOne(fetch = FetchType.LAZY)<br>&nbsp;&nbsp;&nbsp;@JoinColumn(name = "BADGE_TYPE_ID")<br>&nbsp;&nbsp;&nbsp;private BadgeTypeEntity badgeType;<br><br>&nbsp;&nbsp;&nbsp;// Getters and Setters <br>}<br><br>// The C Entity (relation that I eventually want to load fetching LEFT on father)&nbsp;&nbsp;&nbsp;<br>@Entity<br>@Table(name = "addresses", schema = "test_db")<br>public class AddressEntity<br>{<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Id<br>&nbsp;&nbsp;&nbsp;&nbsp;@GeneratedValue(strategy= GenerationType.IDENTITY)<br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "ADDRESS_ID")<br>&nbsp;&nbsp;&nbsp;&nbsp;private Integer addressId;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "DESCRIPTION")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String description;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "CITY")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String city;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "STATE")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String state;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;// The C1 Entity Relation (not wished)<br>&nbsp;&nbsp;&nbsp;&nbsp;@OneToOne(fetch = FetchType.LAZY)<br>&nbsp;&nbsp;&nbsp;&nbsp;@JoinColumn(name = "ADDRESS_TYPE_ID")<br>&nbsp;&nbsp;&nbsp;&nbsp;private AddressTypeEntity addressType;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Getters and Setters <br> }<br><br>// The B1 Entity (relation that I don't want to load) <br>@Entity<br>@Table(name = "badge_types", schema = "test_db")<br>public class BadgeTypeEntity<br>{<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Id<br>&nbsp;&nbsp;&nbsp;&nbsp;@GeneratedValue(strategy= GenerationType.IDENTITY)<br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "BADGE_TYPE_ID")<br>&nbsp;&nbsp;&nbsp;&nbsp;private Integer badgeTypeId;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "CODE")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String code; <br><br>&nbsp;&nbsp;&nbsp;&nbsp;// Getters and Setters <br>}&nbsp;&nbsp;&nbsp;&nbsp;<br><br>// The C1 Entity (relation that I don't want to load) <br>@Entity<br>@Table(name = "address_types", schema = "test_db")<br>public class AddressTypeEntity {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Id<br>&nbsp;&nbsp;&nbsp;&nbsp;@GeneratedValue(strategy= GenerationType.IDENTITY)<br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "ADDRESS_TYPE_ID")<br>&nbsp;&nbsp;&nbsp;&nbsp;private Integer addressTypeId;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;@Column(name = "CODE")<br>&nbsp;&nbsp;&nbsp;&nbsp;private String code;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;// Getters and Setters <br>}&nbsp;&nbsp;&nbsp;&nbsp;<br><br>/**<br>*<br>*&nbsp;&nbsp;&nbsp;Load all UserEntities executing only single query,<br>*&nbsp;&nbsp;&nbsp;fetching RIGHT on BadgeEntity and AddressEntity (@OneToOne relations), <br>*&nbsp;&nbsp;&nbsp;avoiding load of nested BadgeTypeEntity and AddressTypeEntity<br>*<br>**/<br>@Override<br>public List&lt;UserEntity&gt; getUserByFilter()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;CriteriaBuilder cb = em.getCriteriaBuilder();<br>&nbsp;&nbsp;&nbsp;&nbsp;CriteriaQuery&lt;UserEntity&gt; cq = cb.createQuery(UserEntity.class);<br>&nbsp;&nbsp;&nbsp;&nbsp;Root&lt;UserEntity&gt; user = cq.from(UserEntity.class);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;// Fetch User --&gt; Address (wished relation, without nested @OneToOne relations)<br>&nbsp;&nbsp;&nbsp;&nbsp;Fetch&lt;UserEntity, AddressEntity&gt; addressFetch = user.fetch(UserEntity_.address, JoinType.LEFT);<br>&nbsp;&nbsp;&nbsp;&nbsp;// Fetch User --&gt; Badge (wished relation, without nested @OneToOne relations) <br>&nbsp;&nbsp;&nbsp;&nbsp;Fetch&lt;UserEntity, BadgeEntity&gt; badgeFetch = user.fetch(UserEntity_.badge, JoinType.LEFT);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cq.where(cb.and(predicates.toArray(new Predicate[predicates.size()]))).distinct(true);<br>&nbsp;&nbsp;&nbsp;&nbsp;TypedQuery&lt;UserEntity&gt; query = em.createQuery(cq);<br>&nbsp;&nbsp;&nbsp;&nbsp;List&lt;UserEntity&gt; result = query.getResultList();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;return result;<br>}<br><br><br>@Test<br>@Transactional<br>public void getUserByFilter_Test()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UserEntity eUser = userCustomRepository.getUserByFilter().get(0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// At this point, one single query is executed<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("\n********************************");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Name&nbsp;&nbsp;&nbsp;&nbsp;: " + eUser.getName());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Surname : " + eUser.getSurname());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Email&nbsp;&nbsp;&nbsp;: " + eUser.getEmail());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("********************************\n");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Calling get on alrready fetched relation, cause execution of an extra query!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BadgeEntity eBadge = eUser.getBadge();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Badge Code : " + eBadge.getCode());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert.assertNotNull(eUser);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;catch (Exception ex)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex.printStackTrace();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert.fail(ex.getMessage());<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}&nbsp;&nbsp;&nbsp;&nbsp;<br><br><br><br>I configured bytecode enhancement via maven plugin:<br> &lt;build&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugins&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;3.7.0&lt;/version&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;configuration&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;compilerArguments&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;processor&gt;org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor&lt;/processor&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/compilerArguments&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/configuration&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugin&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;plugin&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;org.hibernate.orm.tooling&lt;/groupId&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;hibernate-enhance-maven-plugin&lt;/artifactId&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;${hibernate.version}&lt;/version&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;executions&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;execution&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;configuration&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;failOnError&gt;true&lt;/failOnError&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;enableLazyInitialization&gt;true&lt;/enableLazyInitialization&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/configuration&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;phase&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; compile<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/phase&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;goals&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;goal&gt;enhance&lt;/goal&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/goals&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/execution&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/executions&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugin&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/plugins&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/build&gt;<br><br>{code}<br><br><br><br><br>Executing the query method, I’m expecting the execution of a single query,on User table, fetching right on Badge and Address tables.<br></span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;">With</span> <span class="diffaddedchars" style="background-color:#ddfade;">But with</span> <span class="diffcontext"> Bytecode Enhancement enabled, three different query are executed.<br>It seems that</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;"> with enhancement enable,</span> <span class="diffcontext"> hibernate ignore</span> <span class="diffremovedchars" style="background-color: #ffe7e7; text-decoration:line-through;"> fetches</span> <span class="diffcontext"> configured</span> <span class="diffaddedchars" style="background-color:#ddfade;"> fetches</span> <span class="diffcontext"> into criteria query<br><br><br>{code:java}<br>Hibernate: <br>&nbsp;&nbsp;&nbsp;&nbsp;select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;distinct userentity0_.user_id as user_id1_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.address_id as address_1_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.badge_id as badge_id1_3_2_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.address_id as address_5_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.badge_id as badge_id6_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.email as email2_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.name as name3_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.surname as surname4_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.address_type_id as address_5_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.city as city2_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.description as descript3_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.state as state4_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.badge_type_id as badge_ty4_3_2_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.code as code2_3_2_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.description as descript3_3_2_ <br>&nbsp;&nbsp;&nbsp;&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;users userentity0_ <br>&nbsp;&nbsp;&nbsp;&nbsp;left outer join<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addresses addressent1_ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on userentity0_.address_id=addressent1_.address_id <br>&nbsp;&nbsp;&nbsp;&nbsp;left outer join<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badges badgeentit2_ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on userentity0_.badge_id=badgeentit2_.badge_id <br>&nbsp;&nbsp;&nbsp;&nbsp;where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1=1<br>Hibernate: <br>&nbsp;&nbsp;&nbsp;&nbsp;select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addresstyp0_.address_type_id as address_1_0_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addresstyp0_.code as code2_0_0_ <br>&nbsp;&nbsp;&nbsp;&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;address_types addresstyp0_ <br>&nbsp;&nbsp;&nbsp;&nbsp;where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addresstyp0_.address_type_id=?<br>Hibernate: <br>&nbsp;&nbsp;&nbsp;&nbsp;select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgetypee0_.badge_type_id as badge_ty1_2_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgetypee0_.code as code2_2_0_ <br>&nbsp;&nbsp;&nbsp;&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badge_types badgetypee0_ <br>&nbsp;&nbsp;&nbsp;&nbsp;where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgetypee0_.badge_type_id=?<br><br>********************************<br>Name&nbsp;&nbsp;&nbsp;&nbsp;: Jhon<br>Surname : Doe<br>Email&nbsp;&nbsp;&nbsp;: jhon.doe@gmail.com<br>********************************<br><br>Badge Code : AA11223344<br>{code}<br><br><br><br><br>Instead, without bytecode enhancement, a single query is righty executed:<br><br><br>{code:java}<br>Hibernate: <br>&nbsp;&nbsp;&nbsp;&nbsp;select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;distinct userentity0_.user_id as user_id1_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.address_id as address_1_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.badge_id as badge_id1_3_2_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.address_id as address_5_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.badge_id as badge_id6_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.email as email2_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.name as name3_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userentity0_.surname as surname4_6_0_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.address_type_id as address_5_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.city as city2_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.description as descript3_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addressent1_.state as state4_1_1_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.badge_type_id as badge_ty4_3_2_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.code as code2_3_2_,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badgeentit2_.description as descript3_3_2_ <br>&nbsp;&nbsp;&nbsp;&nbsp;from<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;users userentity0_ <br>&nbsp;&nbsp;&nbsp;&nbsp;left outer join<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;addresses addressent1_ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on userentity0_.address_id=addressent1_.address_id <br>&nbsp;&nbsp;&nbsp;&nbsp;left outer join<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;badges badgeentit2_ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;on userentity0_.badge_id=badgeentit2_.badge_id <br>&nbsp;&nbsp;&nbsp;&nbsp;where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1=1<br><br>********************************<br>Name&nbsp;&nbsp;&nbsp;&nbsp;: Jhon<br>Surname : Doe<br>Email&nbsp;&nbsp;&nbsp;: jhon.doe@gmail.com<br>********************************<br><br>Badge Code : AA11223344<br>{code}<br><br></span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> <script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "EmailMessage",
  "description": "View Issue",
  "potentialAction": {
    "@type": "ViewAction",
        "target": "https://hibernate.atlassian.net/browse/HHH-13203?inbox=true&",
    "name": "View Issue"
      },
  "publisher": {
    "@type": "Organization",
    "name": "Atlassian",
    "url": "https://www.atlassian.com"
  }
}
</script> 
                                        <table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="actions-pattern-container" valign="middle" style="padding: 0; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0"> 
                                                        <table align="left" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                                            <tbody>
                                                                <tr> 
                                                                    <td class="actions-pattern-action-icon-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HHH-13203#add-comment?atlOrigin=eyJpIjoiMzNiNjRhYTU0ZDdmNGZiNGI0YmJmOTNkYzI0ZGQ4MDkiLCJwIjoiaiJ9" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-26a0cc3b-0ee1-485d-bcc1-5b0bf6b94e47" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle"> </a> </td> 
                                                                    <td class="actions-pattern-action-text-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://hibernate.atlassian.net/browse/HHH-13203#add-comment?atlOrigin=eyJpIjoiMzNiNjRhYTU0ZDdmNGZiNGI0YmJmOTNkYzI0ZGQ4MDkiLCJwIjoiaiJ9" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a> </td> 
                                                                </tr> 
                                                            </tbody>
                                                        </table> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <!-- there needs to be content in the cell for it to render in some clients --> 
                                <tr> 
                                    <td class="email-content-rounded-bottom mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #ffffff; border-top: 0; border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly" height="5" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="footer-pattern" style="padding: 0; border-collapse: collapse; padding: 12px 20px"> 
                        <table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="footer-pattern-mobile-separated-links" class="mobile-resize-text" width="100%" colspan="2" style="padding: 0; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> Get Jira notifications on your phone! Download the Jira Cloud app for <a href="https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail" style="color: #3b73af; text-decoration: none">Android</a> or <a href="https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8" style="color: #3b73af; text-decoration: none">iOS</a> 
                                        <hr> </td> 
                                </tr> 
                                <tr> 
                                    <td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> This message was sent by Atlassian Jira <span id="footer-build-information">(v1001.0.0-SNAPSHOT#100097-<span title="20c71fe7db11a5db729e4de6634af659d1661338" data-commit-id="20c71fe7db11a5db729e4de6634af659d1661338}">sha1:20c71fe</span>)</span> </td> 
                                    <td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0; border-collapse: collapse; padding-left: 20px; vertical-align: top"> 
                                        <table style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="footer-pattern-logo-desktop-padding" style="padding: 0; border-collapse: collapse; padding-top: 3px; opacity: 0.150"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-d8d02ad3-5654-4782-84e6-263b242e7ccf" alt="Atlassian logo" title="Atlassian logo" width="192" height="24" class="image_fix"> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
            </tbody>
        </table>   
    
<img border="0" width="1" height="1" alt="" src="http://atlassian.et.e.sparkpost.com/q/OeOejgAqxv3DCaSawyWIwg~~/AAAAAQA~/RgReHkaUPlcLYXRsYXNzaWFudXNCCgAAFBM9XIOYEoFSIGhpYmVybmF0ZS1pc3N1ZXNAbGlzdHMuamJvc3Mub3JnWAQAAAAE">
</body>
</html>