See which of your colleagues or former colleagues are already on Java Link: Check out the Contact Finder
News »Browse Articles » Configuring hibernate
0
Vote Vote

Configuring hibernate

Views 2 Views    Comments 0 Comments    Share Share    Posted 30-07-2009  
Hibernate Configuration

Using XML files for configuring hibernate application is the most widely used approach. This is simple one and less whanges needed in the future. There is two types of configuration we can do using XML files. one is non-managed environment and another one is for managed environment. Here we will explain about the non-managed environment or standalone program. In the managed environment you can use datasource for establishing connection to the database instead directly specifying all the properties in the configuration file.

This sample program uses
configuration.configure().buildSessionFactory() to configure the hibernate application. It assumes that the hibernate.cfg.xml file is placed in the classpath of the project. if you want to change the configuration file name and path then pass as argument in the configuration.configure(”filename”) method.

J2eeBrainHibernateExample.java
package j2eebrain.com.hibernate;

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

/**
* source : www.j2eebrain.com
*/
public class J2eeBrainHibernateExample {
public static void main(String args[]){
Configuration configuration = new Configuration();

// configuring hibernate
SessionFactory sessionFactory = configuration.configure().buildSessionFactory();
}
}

hibernate.cfg.xml
......

Source:
http://www.j2eebrain.com/java-J2ee-configuring-hibernate.html
0
Vote  Vote
Enter your comment:
No Comments For This News

Search News

What's the News?

Post a link to something interesting from another site, or submit your own original writing for the Java community to read.

Most Popular News

Most Recent User Submitted News