Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate generating a query from Named Query that joins on the wrong column?
    primarykey
    data
    text
    <p>I am using named query (hibernate 4).Entity defined as below.</p> <pre><code> @Entity @NamedQuery( name = "findAllProduct", query = "SELECT PC.pincode,PO.description" +" FROM PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION PVPOL" +" INNER JOIN PVPOL.paymentId PID" +" INNER JOIN PVPOL.pincode PC" +" INNER JOIN PVPOL.paymentOptions PO" +" where PVPOL.id = :id" ) public class PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION extends baseEntity.Entity { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int id; @Column(name="Payment_Id") @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="id") private Set&lt;Product_Catalog_Vendor&gt; paymentId; @Column(name="pincode_id") @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="pincode_id") private Set&lt;Pincodes&gt; pincode; @Column(name = "payment_options") @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER,mappedBy="paymentOptions") private Set&lt;Payment_Options&gt; paymentOptions; //Protected setter getter here } </code></pre> <p>Hibernate generating below sql:- </p> <pre><code> select pincode2_.pincode as col_0_0_, paymentopt3_.Description as col_1_0_ from PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION product_ve0_ inner join Product_Catalog_Vendor paymentid1_ on product_ve0_.id=paymentid1_.Id inner join Pincodes pincode2_ on product_ve0_.id=pincode2_.pincode_id inner join payement_options paymentopt3_ on product_ve0_.id=paymentopt3_.payment_options where product_ve0_.id=? </code></pre> <p>Instead of </p> <pre><code>select pincode2_.pincode as col_0_0_, paymentopt3_.Description as col_1_0_ from PRODUCT_VENDOR_PAYMENT_OPTION_LOCATION product_ve0_ INNER JOIN product_catalog_vendor paymentid1_ ON **product_ve0_.payment_id = paymentid1_.id** INNER JOIN PINCODES pincode2_ ON **product_ve0_.pincode_id = pincode2_.pincode_id** INNER JOIN payement_options paymentopt3_ ON **product_ve0_.payment_options=paymentopt3_.payment_options** where product_ve0_.id=1; </code></pre> <p>Product_catalog_vendor class:</p> <pre><code>@Entity public class Product_Catalog_Vendor extends baseEntity.Entity { @Id @Column(name="Id") private int id ; //Setters and getters here } </code></pre> <p>Pincodes Entity:</p> <pre><code>@Entity public class Pincodes extends baseEntity.Entity { @Id private int pincode_id; @Column(name="pincode") private int pincode; //Setters and getters here } </code></pre> <p>payment_options Entity below:</p> <pre><code>@Entity @Table(name="payement_options") public class Payment_Options extends baseEntity.Entity { @Id @Column(name="payment_options") private int paymentOptions; //Setter getter </code></pre> <p>}</p> <p>I have searched on many sites but unable to find the cause behind the scene. Please give me suggestions if i am doing something wrong. some good references would be appreciated. Thanks</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