package resorces;
import java.util.Properties;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.hiberante.api.programetic.Account;
public class HiberanateConfig {
//Property based configuration
private static SessionFactory sessionJavaConfigFactory;
private static SessionFactory buildSessionJavaConfigFactory() {
try {
Configuration configuration = new Configuration();
//Create Properties, can be read from property files too
Properties props = new Properties();
props.put("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
props.put("hibernate.connection.url", "jdbc:oracle:thin:@localhost:1521:XE");
props.put("hibernate.connection.username", "DLAUDIT");
props.put("hibernate.connection.password", "DLAUDIT");
props.put("hibernate.current_session_context_class", "thread");
props.put("hibernate.show_sql", true);
props.put("format_sql", true);
props.put("hibernate.dialect", "org.hibernate.dialect.OracleDialect");
configuration.setProperties(props);
//we can set mapping file or class with annotation
//addClass(Employee1.class) will look for resource
// com/journaldev/hibernate/model/Employee1.hbm.xml (not good)
configuration.addAnnotatedClass(Account.class);
//configuration.addClass(Account.class);
//configuration.addResource("resorces/Account.hbm.xml");
// ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
System.out.println("Hibernate Java Config serviceRegistry created");
SessionFactory sessionFactory = configuration.buildSessionFactory();
return sessionFactory;
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionJavaConfigFactory() {
if(sessionJavaConfigFactory == null) sessionJavaConfigFactory = buildSessionJavaConfigFactory();
return sessionJavaConfigFactory;
}
}
import java.util.Properties;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.hiberante.api.programetic.Account;
public class HiberanateConfig {
//Property based configuration
private static SessionFactory sessionJavaConfigFactory;
private static SessionFactory buildSessionJavaConfigFactory() {
try {
Configuration configuration = new Configuration();
//Create Properties, can be read from property files too
Properties props = new Properties();
props.put("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
props.put("hibernate.connection.url", "jdbc:oracle:thin:@localhost:1521:XE");
props.put("hibernate.connection.username", "DLAUDIT");
props.put("hibernate.connection.password", "DLAUDIT");
props.put("hibernate.current_session_context_class", "thread");
props.put("hibernate.show_sql", true);
props.put("format_sql", true);
props.put("hibernate.dialect", "org.hibernate.dialect.OracleDialect");
configuration.setProperties(props);
//we can set mapping file or class with annotation
//addClass(Employee1.class) will look for resource
// com/journaldev/hibernate/model/Employee1.hbm.xml (not good)
configuration.addAnnotatedClass(Account.class);
//configuration.addClass(Account.class);
//configuration.addResource("resorces/Account.hbm.xml");
// ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
System.out.println("Hibernate Java Config serviceRegistry created");
SessionFactory sessionFactory = configuration.buildSessionFactory();
return sessionFactory;
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionJavaConfigFactory() {
if(sessionJavaConfigFactory == null) sessionJavaConfigFactory = buildSessionJavaConfigFactory();
return sessionJavaConfigFactory;
}
}