-1

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/

http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html/ch01.html#hibernate-gsg-setup-releaseBundle

halfer
  • 19,824
  • 17
  • 99
  • 186
user3198259
  • 178
  • 3
  • 13
  • I've had to fix a lot here to make this readable. Whilst we welcome people who are not native English speakers here, formatting paragraphs without code blocks, and using a spell checker to remove typographical errors, is appreciated. Thanks. – halfer Feb 01 '16 at 08:31
  • Halfer. i agree i am not intended properly.please don't dislike the question. Nobody will answer if dislike the question.If u need i can provide some more details. if anything confusion in my question. – user3198259 Feb 01 '16 at 09:59
  • Don't worry about downvotes - they are just messages to help improve your future questions. I get one every month or two, and very rarely do people explain to me what they did not like about my post. However here I have explained that we like questions to have care and time expended upon them, since they are for posterity and not just the original poster. – halfer Feb 02 '16 at 08:55

1 Answers1

0

I added in my sessionfactory below code. Now I am able to see all imports, namedqueries and collections.

 dialectMappings =
                    dialectMappingsLocator.locateDialectMappings(configuration);
            if (dialectMappings != null) {
                setMappingResources(dialectMappings.getAllMappingResources());
                AbstractDao.setDialectSettings(dialectMappings);
            }
            for(String resource : dialectMappings.getParentDialectMappings().getAllMappingResources()) {
                configuration.addResource(resource);
            }
halfer
  • 19,824
  • 17
  • 99
  • 186
user3198259
  • 178
  • 3
  • 13