title: how to select data from hibernate list on non primary key table in which where clause data is same for all the column
body: <p>I am new to hibernate framework,please provide your insight on this
  I want to populate list based on the where condition,but hibernate list() returns a redundant/duplicate data in the list instead of showing all the records based on the where clause in a non primary key table in which where clause data is same for all the column</p>
  
  <p>i don't have possibility to add primary key.</p>
  
  <p>Below is the code snippet</p>
  
  <p>This is my hibernate.cfg.xml configuration file </p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/oracle&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;root&lt;/property&gt;  
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;mapping class="com.jspiders.app.dto.Office"/&gt;
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is my DTO class</p>
  
  <pre><code>import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="office")
  public class Office {
  
      @Id
      @Column(name = "id")
      private int id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "column3")
      private String column3;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getColumn3() {
          return column3;
      }
  
      public void setColumn3(String column3) {
          this.column3 = column3;
      }
  
      @Override
      public String toString() {
          return "Office [id=" + id + ", name=" + name + ", column3=" + column3 + "]";
  }
  </code></pre>
  
  <p>This is my DAO class</p>
  
  <pre><code>import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.query.Query;
  
  import com.jspiders.app.dto.Office;
  import com.jspiders.app.util.HibernateUtil;
  
  public class OfficeDAO {
      SessionFactory factory = HibernateUtil.getUtility().getSessionFactory();
  
      public List&lt;Office&gt; retrieve() {
          Session s = factory.openSession();
          Query q = s.createQuery("select distinct o from Office o where id=1");
          List&lt;Office&gt; list = q.list();
          for (Office oo : list) {
              System.out.println(oo.toString());
          }
         return list;
      }
  </code></pre>
  
  <p>This is my singleton class</p>
  
  <pre><code>import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  public class HibernateUtil {
  
      private static final HibernateUtil util;
      private SessionFactory factory;
  
      static {
          util=new HibernateUtil();
      }
  
      private HibernateUtil()
      {
          Configuration cfg=new Configuration();
          cfg.configure();
          factory = cfg.buildSessionFactory();
      }
  
  
      public static HibernateUtil getUtility() {
          return util;
      }
  
  
      public  SessionFactory getSessionFactory() {
          return factory;
      }
  
  
      @Override
      protected void finalize() throws Throwable {
  
          if(factory!=null)
              factory.close();
      }
  
  
  this snippet is from my main class
  public static void main(String[] args) {
  
          OfficeDAO dao = new OfficeDAO();
          List&lt;Office&gt; list=dao.retrieve();
  
      }
  </code></pre>
  
  <p>this is my office table creation sql</p>
  
  <pre><code>CREATE TABLE oracle.office
  (
  id INT NOT NULL,
  NAME VARCHAR(30) NOT NULL,
  column3 VARCHAR(30) NOT NULL
  );
  </code></pre>
  
  <p>office table data</p>
  
  <p>id    name  column3
  1      a     qwert
  1      b     abc</p>
  
  <p>This is my Result</p>
  
  <p>Hibernate: select distinct office0_.id as id1_0_, office0_.column3 as column2_0_, office0_.name as name3_0_ from office office0_ where office0_.id=1
  Office [id=1, name=abc, column3=qwert]
  Office [id=1, name=abc, column3=qwert]</p>