how to get all record from table in hibernate

How to get all record from table in hibernate

Let’s understand how to get all record from table in hibernate , Here i will use oracle 10G database and java 8 version , Please make sure before running below program you have to add all hibernate jar files into lib folder and configure build path because this example is on standalone application.

How to get all record from table in hibernate

  1. hibernate.cfg.xml
  2. studentinfo.hbm.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 <property name="">update</property>
 <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
 <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
 <property name="connection.username">system</property>
 <property name="connection.password">manager</property>
 <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
 <mapping resource="com/javagf/bean/StudentInfo.hbm.xml" />


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<!-- Generated 16 Jun, 2017 7:57:05 PM by Hibernate Tools 3.5.0.Final -->
 <class name="com.javagf.bean.StudentInfo" table="STUDENTINFO">
 <id name="roll" type="int">
 <generator class="assigned" />
 <property name="name" type="java.lang.String"></property>
 <property name="address" type="java.lang.String"></property>

package com.javagf.bean;
public class StudentInfo {
 private int roll;
 private String name; 
 private String address;
 public int getRoll() { return roll; }
 public void setRoll(int roll) { this.roll = roll; }
 public String getName() { return name; }
 public void setName(String name) { = name; }
 public String getAddress() { return address; }
 public void setAddress(String address) { this.address = address; }

package com.javagf.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.javagf.bean.StudentInfo;
public class Run {
 public static void main(String[] args) {
 Configuration cfg = new Configuration(); 
 SessionFactory factory = cfg.buildSessionFactory();
 Session session = factory.openSession();

 List<StudentInfo> list = session.createCriteria(StudentInfo.class).list();




[StudentInfo [roll=101, name=Vicky, address=Hyderabad], StudentInfo [roll=102, name=Rahul, address=Pune]]

Related Posts

  1. Why hibernate is better than JDBC
  2. Hibernate Architecture
  3. Steps to create hibernate application in eclipse
  4. Hibernate Mapping and Configuration file
  5. Hibernate SQL Dialects List
  6. Hibernate Query Language
  7. Hibernate ID generator
  8. insert data into table using hibernate example
  9. update record database using hibernate
  10. Delete record database using hibernate

Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: Sales: +91 8085506229