<?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:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            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/jee http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
            ">

	<context:component-scan base-package="com.eactive.eai" />

    <bean id="entityManagerFactory" primary="true"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="packagesToScan"
                  value="com.eactive.eai.data, com.eactive.eai.jpa"></property>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"></bean>
        </property>
        <property name="jpaProperties" ref="hibernateProperties"></property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property
                name="dataSource"
                ref="dataSource">
        </property>
        <property name="entityManagerFactory" ref="entityManagerFactory"></property>
    </bean>

	<jpa:auditing auditor-aware-ref="frameworkAuditorAware" />

    <jpa:repositories
            transaction-manager-ref="transactionManager"
            entity-manager-factory-ref="entityManagerFactory"
            base-package="com.eactive.eai"
            base-class="com.eactive.eai.data.jpa.BaseRepositoryImpl"></jpa:repositories>


	<bean id="entityManager" 
		class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
		<property name="entityManagerFactory"
			ref="entityManagerFactory" />
	</bean>

	<tx:annotation-driven proxy-target-class="true" />

    <util:properties id="hibernateProperties">
        <prop key="hibernate.default_schema">${eai.tableowner}</prop>
        <prop key="hibernate.hbm2ddl.auto">validate</prop>
        <prop key="hibernate.format_sql">true</prop>
        <prop key="hibernate.show_sql">false</prop>
        <prop key="hibernate.dialect">${hibernate.dialect:org.hibernate.dialect.Oracle12cDialect}</prop>
        <prop key="hibernate.jdbc.batch_size">100</prop>
        <prop key="hibernate.jdbc.fetch_size">100</prop>
        <prop key="hibernate.cache.use_second_level_cache">false</prop>
        <prop key="hibernate.cache.use_query_cache">false</prop>
        <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
        <prop key="hibernate.cache.use_minimal_puts">true</prop>
        <prop key="hibernate.physical_naming_strategy">com.eactive.eai.data.jpa.CustomPhysicalNamingStrategy</prop>
        <!-- <prop key="hibernate.generate_statistics">true</prop> -->
        <prop key="javax.persistence.schema-generation.create-source">metadata</prop>
        <prop key="javax.persistence.schema-generation.scripts.action">update</prop>
        <prop key="javax.persistence.schema-generation.scripts.create-target">update.sql</prop>
        <prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
    </util:properties>
</beans>