Hibernate : General flow of Hibernate communication with RDBMS

General steps:
1. Load the Hibernate configuration file and create configuration object. It will automatically load all hbm           mapping files.
2. Create session factory from configuration object
3. Get one session from this session factory.
4. Create HQL query.
5. Execute query to get list containing Java objects.

Example:
Retrieve list of employees from Employee table using Hibernate.

/* Load the hibernate configuration file */
Configuration cfg = new Configuration(); cfg.configure(CONFIG_FILE_LOCATION);

/* Create the session factory */
SessionFactory sessionFactory = cfg.buildSessionFactory();

/* Retrieve the session */
Session session = sessionFactory.openSession();

/* create query */
Query query = session.createQuery(“from  EmployeeBean”);

/* execute query and get result in form of Java objects */ List
fina lList = query.list();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s