Create a class containing the HibernateProperties and SessionFactory objects. Sort of:
public class HibernateSessionFactory { private static final long serialVersionUID = 1L; private static Log log = LogFactory.getLog(HibernateSessionFactory.class); private Resource[] mappingLocations; private Properties hibernateProperties; private SessionFactory factory;
Well, if you can use Spring later and introduce this class with database connection details, then assign this HibernateSessionFactory to the corresponding DAO classes.
I have done this before, more or less it looks like this:
<bean id="mapHibernateFactory" class="com.geofencing.dao.hibernate.HibernateSessionFactory" init-method="init" destroy-method="dispose" scope="singleton"> <property name="mappingResources"> <list> ..... your hibernate mapping files ..... </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.hbm2ddl.auto">false</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">false</prop> <prop key="hibernate.connection.isolation">4</prop> <prop key="hibernate.connection.autocommit">false</prop> <prop key="hibernate.connection.url">${jdbc.url}</prop> <prop key="hibernate.connection.username">${jdbc.username}</prop> <prop key="hibernate.connection.password">${jdbc.password}</prop> <prop key="hibernate.connection.driver_class">${jdbc.driverClassName}</prop> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.c3p0.min_size">5</prop> <prop key="hibernate.c3p0.max_size">20</prop> <prop key="hibernate.c3p0.timeout">1800</prop> <prop key="hibernate.c3p0.max_statements">50</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider</prop> <prop key="net.sf.ehcache.configurationResourceName">WEB-INF/ehcache.xml</prop> <prop key="hibernate.cglib.use_reflection_optimizer">false</prop> <prop key="hibernate.connection.zeroDateTimeBehavior">convertToNull</prop> <prop key="hibernate.connection.autoReconnect">true</prop> <prop key="hibernate.connection.autoReconnectForPools">true</prop> </props> </property> </bean>
I donβt know how to do this with annotation.
user591593
source share