Note that there are some explanatory texts on larger screens.

plurals
  1. PO(1+N) selects with OnetoOne associations
    primarykey
    data
    text
    <p>Considering the following model:</p> <pre><code>@Entity public class User { @Id @Column(name = "USER_ID") private Long userId; @Column(name = "FIRST_NAME") private String firstName; @Column(name = "LAST_NAME") private String lastName; @OneToOne @PrimaryKeyJoinColumn private UserExt userExt; ... //getters and setters } @Entity public class UserExt { @Id @Column(name="USER_ID") private Long id; private String cdpId; private Date lastChanged; ... //getters and setters } </code></pre> <p>when executing :</p> <pre><code>Query query = session.createQuery("from User"); List&lt;User&gt; list = query.list(); </code></pre> <p>Hibernate executes </p> <pre><code>Hibernate: select user0_.USER_ID as USER1_0_, user0_.FIRST_NAME as FIRST2_0_, user0_.LAST_NAME as LAST3_0_, user0_.EXT_USERNAME as EXT4_0_ from USER user0_ Hibernate: select userext0_.USER_ID as USER1_1_0_, userext0_.cdpId as cdpId1_0_, userext0_.lastChanged as lastChan3_1_0_ from USER_EXT userext0_ where userext0_.USER_ID=? Hibernate: select userext0_.USER_ID as USER1_1_0_, userext0_.cdpId as cdpId1_0_, userext0_.lastChanged as lastChan3_1_0_ from USER_EXT userext0_ where userext0_.USER_ID=? ... ... </code></pre> <p>Using a query with specific properties works (select u.firstName, u.userExt.cdpId).</p> <p>However since I want the full User Entity ("from User"), hibernate generates one select for each result row in the first.</p> <p>I don't get it since the default fetch strategy should be LAZY not EAGER. Forcing it to LAZY didn't fix the problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload