title: Fetching data from table using hibernate
body: <p>I am able to persist objects in relational database using hibernate. 
          please look at following code.</p>
  
  <pre><code>package one;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.SecondaryTable;
  import javax.persistence.Table;
  
  @Entity
  public class Customer {
  
      @Id
      private int customerId;
      private String customerName;
      private String customerAddress;
      private int creditScore;
      private int rewardPoints;
  
      public Customer()
      {
  
      }
  
      public Customer(int customerId,String customerName,String customerAddress,int creditScore,int rewardsPoints)
      {
          this.customerId=customerId;
          this.customerAddress=customerAddress;
          this.creditScore=creditScore;
          this.customerName=customerName;
          this.rewardPoints=rewardsPoints;
      }
  
      public int getCustomerId() {
          return customerId;
      }
      public void setCustomerId(int customerId) {
          this.customerId = customerId;
      }
      public String getCustomerName() {
          return customerName;
      }
      public void setCustomerName(String customerName) {
          this.customerName = customerName;
      }
  
  
      public String getCustomerAddress() {
          return customerAddress;
      }
      public void setCustomerAddress(String customerAddress) {
          this.customerAddress = customerAddress;
      }
  
  
      public int getCreditScore() {
          return creditScore;
      }
      public void setCreditScore(int creditScore) {
          this.creditScore = creditScore;
      }
  
      public int getRewardPoints() {
          return rewardPoints;
      }
      public void setRewardPoints(int rewardPoints) {
          this.rewardPoints = rewardPoints;
      }
  
  }
  </code></pre>
  
  <p>Then to save object of this class i used following class. following class creates the object of class Customer and saves that object in database then again retrieves it and prints the CustomerName property of every saved object.  </p>
  
  <pre><code>package one;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  public class TestCustomer {
      public static void main(String args[])
      {
          Customer cust = new Customer(13,"Sara","Banglore",9000,60);
  
  
          SessionFactory factory = new Configuration().configure().buildSessionFactory();
          Session session = factory.openSession();
          session.beginTransaction();
          session.save(cust);
          session.getTransaction().commit();
          session.close();
  
          session = factory.openSession();
          session.beginTransaction();
          List list = session.createQuery("FROM Customer").list();
          Iterator iterator = list.iterator();
  
          while(iterator.hasNext())
          {
              Customer custA = (Customer)iterator.next();
              System.out.println("First Name\t"+custA.getCustomerName());
          }
          session.getTransaction().commit();
          session.close();
  
      }
  }
  </code></pre>
  
  <p>I executed above code quite a number of times. code is running fine. it is able to fetch all objects which are saved. 
  but then i used oracle toad and fired a <code>sql</code> statement as</p>
  
  <pre><code>Insert into Customer(CUSTOMERID,CREDITSCORE,CUSTOMERNAME,REWARDPOINTS,CUSTOMERADDRESS)
  VALUES(87,4000,'Saurabh',20,'Kalwa');
  </code></pre>
  
  <p>record gets stored in the table but when i execute above code, i am not able to fetch this record. 
  one conclusion i can draw is hibernate only returns <code>persisted objects</code>, but still is there any other way i can get all records ? </p>