Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Injecting Hibernate SessionFactory when using LocalContainerEntityManagerFactoryBean

$
0
0
I am trying to obtain Hibernate SessionFactory. I was unsuccessful so far.
I am using Java Config (no XML files) and Annotations.
My persistence config is the following:
Code:

@Bean
        public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

                log.info("Scanning the following packages for JPA entities: ");

                LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
                emf.setDataSource(ds);
                emf.setPackagesToScan("com.msi.nsi.cmm.jpa");

                HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
                adapter.setDatabase(Database.MYSQL);
                adapter.setShowSql(true);

                Properties jpaProperties = new Properties();
                jpaProperties.setProperty("hibernate.format_sql", "true");
                jpaProperties.setProperty("hibernate.dialect",
                                "org.hibernate.dialect.MySQLDialect");

                jpaProperties.setProperty("hibernate.cache.provider_class",
                                "org.hibernate.cache.SingletonEhCacheProvider");
                jpaProperties.setProperty("hibernate.cache.provider_configuration",
                                "/com/msi/nsi/cmm/framework/ehcache-cmm.xml");
                jpaProperties.setProperty("hibernate.cache.use_second_level_cache",
                                "true");
                jpaProperties.setProperty("hibernate.cache.use_query_cache", "true");
                jpaProperties.setProperty("hibernate.cache.region.factory_class",
                                "org.hibernate.cache.ehcache.EhCacheRegionFactory");

                emf.setJpaVendorAdapter(adapter);
                emf.setJpaProperties(jpaProperties);

                return emf;
        }

I am tring to @Inject SessionFactory in my repository object but I am getting:
Failed to load ApplicationContext.

Do you have any way to extract SessionFactory from this environment?

Viewing all articles
Browse latest Browse all 297

Trending Articles