We are upgrading Hibernate 3 and Spring 3 to Hibernate4 and Spring4.
My sessionfactory code in Hibernate 4 is like following.
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
public class PMLSessionFactoryBean extends LocalSessionFactoryBean {
private DialectMappingsLocator dialectMappingsLocator;
/**
* @param dialectMappingsLocator The dialectMappingsLocator to set.
*/
public void setDialectMappingsLocator(DialectMappingsLocator dialectMappingsLocator) {
this.dialectMappingsLocator = dialectMappingsLocator;
}
@Override
protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder localSessionFactoryBuilder){
SessionFactory sessionFactory = null;
Configuration configuration = super.getConfiguration();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().
applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(builder.build());
return sessionFactory;
}
}
My application context xml like below
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="PMLJdbcProperties" class="com.fusionone.core.util.FilteredProperties">
<property name="location" value="classpath:jdbc.properties" />
<constructor-arg value="pml" />
</bean>
<bean id="PMLDataSource"
class="com.fusionone.core.db.pool.MonitoredDataSourceFactory"
destroy-method="close" factory-method="createDataSource">
<constructor-arg ref="PMLJdbcProperties" />
</bean>
<bean id="PMLDefaultDialectSettings" class="com.fusionone.pml.bean.PMLDialectMappings"
lazy-init="true" autowire-candidate="false">
<property name="mappingResources">
<list>
<value>hibernate-mappings/BrewApp.hbm.xml</value>
<value>hibernate-mappings/ExtShare.hbm.xml</value>
<value>hibernate-mappings/MergedContact.hbm.xml</value>
<value>hibernate-mappings/MergedContactLink.hbm.xml</value>
</list>
</property>
<property name="daoInterfaceImpls">
<map>
<entry key="DeletedContactDao"
value="com.fusionone.pml.dao.hibernate.DeletedContactDaoImpl" />
<entry key="ExtShareDao"
value="com.fusionone.pml.dao.hibernate.ExtShareDaoImpl" />
<entry key="MergedContactDao"
value="com.fusionone.pml.dao.hibernate.MergedContactDaoImpl" />
<entry key="MergedContactLinkDao"
value="com.fusionone.pml.dao.hibernate.MergedContactLinkDaoImpl" />
</map>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="PMLSessionFactory" />
</property>
<property name="nestedTransactionAllowed" value="true" />
</bean>
<bean id="PMLSessionFactory" class="com.fusionone.pml.bean.PMLSessionFactoryBean">
<property name="dataSource">
<ref bean="PMLDataSource" />
</property>
<property name="dialectMappingsLocator" ref="dialectMappingsLocator" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.jdbc.use_get_generated_keys">
false
</prop>
<prop key="hibernate.cache.region.provider_class">
org.hibernate.cache.ehcache.EhCacheRegionFactory
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.jdbc.batch_size">150</prop>
</props>
</property>
</bean>
Previously in Hibernate 3 super.configuration loading all imports, namedqueries and collections.When we upgrade to hibernate 4 we are not seeing any imports and namedqueries are loading to configuraiton. My transaction manager is loading the pmlsessionfactory and pmlsessionfactorybean loading my datasource and mappings. while debugging We saw the configuration loading my datasource and hibernate property values means datasource name and schema name every thing is loaded. but namedqueries, imports, collections and tables are not loaded.
Is anything wrong on my code or application xml? We have our own datasource class that will have all connection pooling mechanism. Also I modified lot of imports while upgrading to Hibernate 4 is that causing this issue or any thing more I need to add like jars. I am using hibernate-core 4.3.11, hibernate-ehcache 4.3.11, ehcache.2.7.0, hibernate-jpa-2.1-api.1.0.0 final, hibernate-entitymanager.4.3.11, hibernate-commons-annotations 4.0.5 and infinitespan jars in myclasspath. I added jars according to below link.
https://jsoftbiz.wordpress.com/2013/03/14/hibernate-4-and-ehcache-higher-than-2-4-3/