I am using Spring to hold a session factory in the application scope.
This is what it executes at deploy time:
Code:
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
...
URL configUrl = HibernateFactoryBean.class.getResource(PATH_PACKAGE_CONFIG_HIBERNATE);
Configuration configuration = new Configuration();
this.sessionFactory = configuration.configure(configUrl).buildSessionFactory();
This is my configuration file:
Code:
<?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">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/filehosting</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">false</property>
<mapping resource="com/filehosting/hibernate/conf/hibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>
When I deploy the web application, it builds the session factory and it is ready to use.
If I deploy the web application, but the database server (MySQL) is not running, the server stops at Configuration.buildSessionFactory() and waits for the database server to respond.
Is this the expected behavior?
Cam I set a timeout for this?
Can the session factory be made without the database connection?