0

I have my hibernate entity manager factory declared in jpa.xml, hazecast configured in hazelcast.xml and I have domain model setup and I have corresponding componentContext.xml present in the domain model project where my entity manager factory class is implemented in it. But the problem I am facing is that my bean in componentContext.xml is getting intialized in a loop (observed from hibernate.log)

My Web.xml has only com.sun.faces.config.ConfigureListener listenere configured.

My Stack Spring - 4.3.8 Hibernate - 5.0.10-FINAL hazelcast-hibernate5 - 1.3.0

JPA.xml

<?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:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans.xsd 
                           http://www.springframework.org/schema/context 
                           http://www.springframework.org/schema/context/spring-context.xsd">

  <context:property-placeholder location="classpath:dataSources.properties" />

  <!-- Default JPA configuration for OpenJPA and Hibernate -->


  <!-- Hibernate configuration -->
  <bean id="hibernateEntityManagerFactory" abstract="true" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaPropertyMap">
      <map>
        <entry key="hibernate.max_fetch_depth" value="3" />
        <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
        <entry key="hibernate.enable_lazy_load_no_trans" value="true" />
        <entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
        <entry key="hibernate.current_session_context_class" value="jta" />

      </map>
    </property>
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="database" value="${dbDialect}" />
      </bean>
    </property>
  </bean>

  <alias name="hibernateEntityManagerFactory" alias="entityManagerFactory" />

</beans>

componentContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
  xmlns:jpa="http://www.springframework.org/schema/data/jpa">

  <context:component-scan base-package="com.volvo.myfirstdomain.base />
  <context:annotation-config />

  <!-- JPA EntityManagerFactory -->
  <!-- Based on choice of implementation between OpenJPA and Hibernate, parent attribute in bean should be set. For OpenJPA: parent = "openJpaEntityManagerFactory" 
    For Hibernate: parent = "hibernateEntityManagerFactory" Here, OpenJPA is chosen as you can see below. -->
  <bean id="myDomainEntityManagerFactory" parent="entityManagerFactory">
    <property name="persistenceUnitName" value="MYDomainPU" />
    <property name="packagesToScan" value="com.volvo.myfirstdomain.entity" />

    <property name="jpaProperties">
      <props>
        <prop key="hibernate.default_schema">DOMAIN_ONE</prop>
        <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect </prop>
        <prop key="hibernate.cache.region.factory_class">com.hazelcast.hibernate.HazelcastCacheRegionFactory</prop>
        <prop key="hibernate.cache.use_second_level_cache">true</prop>
        <prop key="hibernate.cache.use_query_cache">true</prop>
        <prop key="javax.persistence.sharedCache.mode">ENABLE_SELECTIVE</prop>

      </props>
    </property>

  </bean>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <constructor-arg ref="dataSource" />
  </bean>
</beans>

I have tried debugging multiple times but I am not able to figure out why the initialzing is happening multiple times (as if in a loop). Any pointers greatly appreciated!

user1734698
  • 157
  • 2
  • 2
  • 17

1 Answers1

1

I finally figured out the reason! There was an additional @ComponentScan annotation specified in the application configuration class which was causing the loop to be triggered.

user1734698
  • 157
  • 2
  • 2
  • 17