com.imos.hibernate.HibernateConnectionTest.java Source code

Java tutorial

Introduction

Here is the source code for com.imos.hibernate.HibernateConnectionTest.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imos.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author Alok
 */
public class HibernateConnectionTest {

    public static void main(String[] args) {

        try (SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory()) {
            try (Session session = sessionFactory.openSession()) {
                System.out.println(session);
            } catch (Exception e) {
                System.out.println(e.getCause().toString() + " : " + e.getMessage());
                e.printStackTrace();
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}