Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created June 9, 2013 20:17
Show Gist options
  • Save hagbarddenstore/5745046 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/5745046 to your computer and use it in GitHub Desktop.
I have three Maven projects in Netbeans: Domain; Server; Web. The HibernateUtility.java is defined in the Domain project at src/main/java/com/company/product/domain/HibernateUtility.java The hibernate.hbm.xml is defined in the Domain project at src/main/resources/hibernate.hbm.xml I'm trying to use HibernateUtility from the Web project, but it d…
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.username">product</property>
<property name="connection.password">product</property>
<property name="connection.url">jdbc:postgresql://localhost/product</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<!-- Disable the second level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="current_session_context_class">thread</property>
<!-- Comment the below line to stop auto-creating the database -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="mappings/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
package com.company.product.domain;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtility {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration()
.configure("hibernate.cfg.xml")
.buildSessionFactory();
} catch (Throwable exception) {
System.err.println("Initial SessionFactory creation failed" + exception);
throw new ExceptionInInitializerError(exception);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment