Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is Hibernate selecting same columns 4 times? Help with Mapping?
    primarykey
    data
    text
    <p>My classes look like these. Why does the same column get selected 4 times? What is problem with the mapping?</p> <pre><code>@Entity @Table(name="CLIENTS") public class Client implements Serializable { @Id @GeneratedValue @Column(name="GENERATED_ID") private Long id; @Column(name="NAME") private String name; @OneToMany(cascade=CascadeType.ALL, mappedBy="client", fetch=FetchType.EAGER) private Map&lt;ParamPK, Param&gt; params = new HashMap&lt;ParamPK, Param&gt;(); } @Entity @Table(name="PARAMS") public class Param implements Serializable { @EmbeddedId private ParamPK paramPK; @Column(name="VALUE") private String value; @ManyToOne @MapsId("clientId") private Client client; } @Embeddable public class ParamPK implements Serializable { @Column(name="PARAM_KEY") private String key; @Column(name="CLIENT_GENERATED_ID") private Long clientId; } </code></pre> <p>The queries generated by select gets same column 4 times.</p> <pre><code>/* from Client */ select client0_.GENERATED_ID as GENERATED1_1_, client0_.NAME as NAME1_ from CLIENTS client0_ /* load one-to-many Client.params */ select params0_.client_GENERATED_ID as client3_1_1_, params0_.client_GENERATED_ID as client3_1_, params0_.PARAM_KEY as PARAM1_1_, params0_.CLIENT_GENERATED_ID as CLIENT3_1_, params0_.client_GENERATED_ID as client3_0_0_, params0_.PARAM_KEY as PARAM1_0_0_, params0_.VALUE as VALUE0_0_ from PARAMS params0_ where params0_.client_GENERATED_ID=? </code></pre> <p>Note using Hibernate 3.5.3. Rest boilerplate code has been removed as irrelevant.</p>
    singulars
    1. This table or related slice is empty.
    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