Hibernate Overview

It is just reference Services.

Visit here : http://www.hibernate.org

Usage Example

services.xml

<?xml version="1.0" encoding="UTF-8"?>

<services>
	<service id="HibernateService" 
	  class="sunheart.service.hibernate.DefaultHibernateService" />
</services>                  
          

Java code

package example;

import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import sunheart.service.ServiceManager;
import sunheart.service.hibernate.HibernateService;

public class HibernateTest {

    public static void main(String[] args) {

        // it require 'hibernate.cfg.xml' file on classpath.
        HibernateService service = (HibernateService) ServiceManager
                .lookupService(HibernateService.id);

        Session session = null;
        Transaction tx = null;
        Object obj = null;
        try {
            session = service.openSession();
            tx = session.beginTransaction();

            // you need some mapping....
            Object entity = new Object();

            session.save(entity);

            tx.commit();

        } catch (Exception e) {
            e.printStackTrace();
            HibernateService.tryRollback(tx);
        } finally {
            HibernateService.tryFlushAndCloseSession(session);
        }

    }
}