<!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-management--avatars.us-west-2.prod.public.atl-paas.net/5c04bf6c470dea35d6932be9/6c1f07c0-084f-4b2b-9b35-5cddf7ed9fa6/128?size=48&s=48" 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="trandung" style="color:#6c797f;; color: #3b73af; text-decoration: none" id="email_trandung" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5c04bf6c470dea35d6932be9"> James Tran Dung </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"> </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=eyJpIjoiZmJhMTJlYmRhMmIxNGVjYjgxZWZhYzU4M2RjMGZhOTAiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none">Hibernate ORM</a> / <a href="https://hibernate.atlassian.net/browse/HHH-14040?atlOrigin=eyJpIjoiZmJhMTJlYmRhMmIxNGVjYjgxZWZhYzU4M2RjMGZhOTAiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-4cf6a940-ecc1-4aa4-b0e2-28fa6cc90a14" height="16" width="16" border="0" align="absmiddle" alt="Bug" style="vertical-align: text-bottom"></a> <a href="https://hibernate.atlassian.net/browse/HHH-14040?atlOrigin=eyJpIjoiZmJhMTJlYmRhMmIxNGVjYjgxZWZhYzU4M2RjMGZhOTAiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none">HHH-14040</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-14040?atlOrigin=eyJpIjoiZmJhMTJlYmRhMmIxNGVjYjgxZWZhYzU4M2RjMGZhOTAiLCJwIjoiaiJ9" style="color: #3b73af; text-decoration: none">@LazyToOne(LazyToOneOption.NO_PROXY) relationship fields executing additional queries</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="trandung" style="color:#6c797f;; color: #3b73af; text-decoration: none" id="email_trandung" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5c04bf6c470dea35d6932be9"> James Tran Dung </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">Version: <br><br>* Spring Boot v2.2.7<br>* Hibernate v5.4.15.Final<br>* {{spring-data-jpa-entity-graph}} v2.2.8<br><br>I have the following {{@Entity}} in my application.<br><br>{code:java}@Entity(name="DemoAccount")<br>@Table(name="staff")<br>@Getter @Setter @FieldNameConstants<br>@NoArgsConstructor<br>public class Account {<br> @Id<br> @GeneratedValue(strategy=GenerationType.IDENTITY)<br> protected Long id;<br> @Column(name="username", nullable=false)<br> private String userId;<br> private String name;<br><br> @ManyToOne(fetch=FetchType.LAZY)<br> @LazyToOne(LazyToOneOption.NO_PROXY)<br> @LazyGroup("nationality")<br> @JoinColumn(name="nationality", referencedColumnName="code")<br> private Nationality nationality;<br>}<br><br>@Entity(name="DemoNationality")<br>@Table(name="nationality ")<br>@Getter @Setter @FieldNameConstants<br>@NoArgsConstructor<br>public class Nationality {<br> @Id<br> @GeneratedValue(strategy=GenerationType.IDENTITY)<br> protected Long id;<br> @Column(name="code", nullable=false)<br> private String code;<br> private String name;<br>}{code}<br><br>I'm using the following {{@Repository}} to look for {{Account}}.<br><br>{code:java}@Repository<br>public interface AccountRepo extends EntityGraphJpaRepository<Account, Long> {<br> Optional<Account> findByUserId(String userId, EntityGraph entityGraph);<br>}{code}<br><br>My test endpoint contains a simple method.<br><br>{code:java}@CustomerTransactional<br>@GetMapping("/profile")<br>public void testProfile(@RequestParam String userId) {<br> Optional<Account> account = accountRepo.findByUserId(userId, EntityGraphs.create(Account.Fields.nationality));<br> if (account.isPresent()) {<br> System.out.println(account.get().getName());<br> System.out.println(account.get().getNationality().getName());<br> }<br>}{code}<br><br>When I execute this endpoint, this is what I'm seeing in the log.<br><br>{code:java}2020-05-24 16:18:26,492 DEBUG [http-nio-9000-exec-1] org.hibernate.SQL : <br> /* select<br> generatedAlias0 <br> from<br> DemoAccount as generatedAlias0 <br> where<br> generatedAlias0.userId=:param0 */ select<br> account0_.id as id1_61_0_,<br> nationalit1_.id as id1_35_1_,<br> account0_.name as name4_61_0_,<br> account0_.username as username6_61_0_,<br> nationalit1_.code as code2_35_1_,<br> nationalit1_.name as name4_35_1_<br> from<br> staff account0_ <br> left outer join<br> nationality nationalit1_ <br> on account0_.nationality=nationalit1_.code <br> where<br> account0_.username=?<br>2020-05-24 16:18:26,492 TRACE [http-nio-9000-exec-1] org.hibernate.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [90000010]<br>Edgar Rey Tann<br>2020-05-24 16:18:26,506 DEBUG [http-nio-9000-exec-1] org.hibernate.SQL : <br> /* sequential select<br> com.ft.demo.db.customer.domain.Account */ select<br> account_.nationality as nationa22_61_ <br> from<br> staff account_ <br> where<br> account_.id=?<br>2020-05-24 16:18:26,507 TRACE [http-nio-9000-exec-1] org.hibernate.type.descriptor.sql.BasicBinder : binding parameter [1] as [BIGINT] - [660]<br>Indonesian{code}<br><br>As you can see, in the middle of the account name and the nationality name, there's an extra query just to select the</span> <span class="diffaddedchars" style="background-color:#ddfade;"> {{</span> <span class="diffcontext"> nationality</span> <span class="diffaddedchars" style="background-color:#ddfade;">}}</span> <span class="diffcontext"> field. It means if I have 50 records, 50 additional queries got executed. May I know how I can fix this behaviour?<br><br>Below is what I used in pom.xml to activate Hibernate Bytecode Enhancer<br><br>{code:java}<build><br> <plugins><br> <plugin><br> <groupId>org.hibernate.orm.tooling</groupId><br> <artifactId>hibernate-enhance-maven-plugin</artifactId><br> <version>${hibernate.version}</version><br> <executions><br> <execution><br> <configuration><br> <failOnError>true</failOnError><br> <enableLazyInitialization>true</enableLazyInitialization><br> <enableDirtyTracking>true</enableDirtyTracking><br> <enableAssociationManagement>true</enableAssociationManagement><br> </configuration><br> <goals><br> <goal>enhance</goal><br> </goals><br> </execution><br> </executions><br> </plugin><br> </plugins><br> </build>{code}</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-14040?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-14040#add-comment?atlOrigin=eyJpIjoiZmJhMTJlYmRhMmIxNGVjYjgxZWZhYzU4M2RjMGZhOTAiLCJwIjoiaiJ9" 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-22f71268-0485-4ac4-acdc-f1340d9d8716" 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-14040#add-comment?atlOrigin=eyJpIjoiZmJhMTJlYmRhMmIxNGVjYjgxZWZhYzU4M2RjMGZhOTAiLCJwIjoiaiJ9" 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"> </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#100127-<span title="ff24dc8ebb7c671d6f98aa545c62f3b905b0d71c" data-commit-id="ff24dc8ebb7c671d6f98aa545c62f3b905b0d71c}">sha1:ff24dc8</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-71b15097-f956-4a0d-927a-3263df233590" 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>
</body>
</html>