Featured Post

Hibernate Sample Ex

import java.io.InputStream;
import java.util.Properties;

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

/**
* @author Venkata Sitaram P - sitaram.pv
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ConfigurationEx {

public static void main( String[] args ) {
try{
SessionFactory sf = null;
//sf = configureUsingHibernateConfigPropertiesFile();
//sf = configureUsingProperty();
//sf = configureUsingHibernateCfg();
//sf = configureUsingPropertiesFile();
sf = configureUsingOtherCfgFileName();
sf.getCurrentSession().beginTransaction();
System.out.println( "Session Factor ::" +
sf.getCurrentSession().connection().getTransactionIsolation() );
}
catch( Exception e ){
e.printStackTrace();
}
}

private static SessionFactory configureUsingProperty() throws Exception
{
return new Configuration().setProperty(
"hibernate.connection.driver_class", "COM.ibm.db2.jdbc.net.DB2Driver" )
.setProperty( "hibernate.connection.password", "rating"
).setProperty( "hibernate.connection.username",
"admin" ).setProperty( "hibernate.connection.url",
"jdbc:db2:C90003/KKHIB" ).setProperty(
"hibernate.dialect",
"org.hibernate.dialect.DB2Dialect" ).buildSessionFactory();
}

private static SessionFactory configureUsingHibernateCfg() throws
Exception {
return new Configuration().configure().buildSessionFactory();
}

private static SessionFactory configureUsingOtherCfgFileName() throws
Exception {
return new
Configuration().configure("Otherhibernate.cfg.xml").buildSessionFactory();
}

private static SessionFactory configureUsingPropertiesFile() throws
Exception {
InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
"HibernateConfig.properties" );
Properties hibernateProp = new Properties();
hibernateProp.load( inputStream );
return new Configuration().configure().addProperties( hibernateProp
).buildSessionFactory();
}

private static SessionFactory
configureUsingHibernateConfigPropertiesFile() throws Exception {
InputStream inputStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
"hibernate.properties" );
Properties hibernateProp = new Properties();
hibernateProp.load( inputStream );
return new Configuration().setProperties( hibernateProp
).buildSessionFactory();
}
}

This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit us at http://www.polaris.co.in

Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...