title: Hibernate createNativeQuery returns duplicate rows
body: <p>I have 2 database tables <strong>Customer</strong> and <strong>Items</strong> with 1 -> many relation. To fetch data from database i am using the following query.</p>
  
  <blockquote>
    <p>select customer.id, customer.name, items.itemName, items.itemPrice from testdb.customer INNER JOIN items ON items.customer_Id = customer.id</p>
  </blockquote>
  
  <p>I have an entity class Customers</p>
  
  <pre><code>@Entity    
  public class Customer{
  
  @Id
  private int id;
  
  @Column
  private String name;
  
  @Column
  private String itemName;
  
  @Column
  private int itemPrice;
  
  public Customer() {}
   //Getter and setter are here
  .......
  }
  </code></pre>
  
  <p>in Service class i have the following code.</p>
  
  <pre><code>@GET @Path("/getCustomerInfo")
  @Produces(MediaType.APPLICATION_JSON)
  public List getCustomerInfo() {
      CustomerDao dao = new CustomerDao();
      return dao.getBuildingsCustomerInfo();
  }
  </code></pre>
  
  <p>in my DAO class i have the following code</p>
  
  <pre><code>public List&lt;Customer&gt; getCustomerInfo(){
      Session session = SessionUtil.getSession();
      String queryString = "the above mentioned query";
      List&lt;Customer&gt; customerInfo = session.createNativeQuery(queryString, Customer.class) ;
      session.close();
      return customerInfo;
  }
  </code></pre>
  
  <p>I am getting the following JSON response from the service</p>
  
  <pre><code>[id:1, name:"Alfred", itemName:"jeans", itemprice:10],[id:1, name:"Alfred", itemName:"jeans", itemprice:10],[id:2, name:"James", itemName:"watch", itemPrice:20 ],[id:2, name:"James", itemName:"watch", itemPrice:20 ], [id:2, name:"James", itemName:"watch", itemPrice:20 ]
  </code></pre>
  
  <p>The number of results are 5 which is correct But 2nd result is a copy of 1st, 4th and 5th are copies of 3rd. In 2nd, 4th and 5th results the itemName and the itemPrice should be different. </p>
  
  <p>if I use <code>createSQLQuery(queryString);</code> instead of <code>createNativeQuery(queryString, Customer.class);</code> I am getting the correct result but without entity attribut names. </p>
  
  <pre><code>[1, "Alfred", "jeans", 10],[1, "Alfred", "shirt", 15],[2, "James", "watch", 20], [2, "James", "coffee", 25], [2, "James", "drinks", 30]
  </code></pre>
  
  <p>I have seen number of articles but could not find the solution. I have to use createNativeQuery() not createSQLQuery() because I need to map the entity class attributes. Please let me know if i am doing something wrong.</p>