JPA entityManagerFactory配置详解

以下是本人的一些理解 如有误的地方欢迎指出 谢谢!

jpa.LocalContainerEntityManagerFactoryBean 与 hibernate的sessionFactory一样都实现了对session的操作

LocalContainerEntityManagerFactoryBean的优势在于当系统需要更换orm框架时不需要太多改动 兼容性好 

缺点则是无法使用一些hibernate session的高级功能

下面我们来看LocalContainerEntityManagerFactoryBean 的配置

    
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSourceProxy" />
        <property name="packagesToScan" ref="com.ssharing.basicflt.**.entity" />

        
        <property name="persistenceUnitName" value="${jpa.persistenceUnitName}" />
        
        <property name="persistenceProvider">
            <bean class="org.hibernate.ejb.HibernatePersistence" />
        property>
        
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="${jpa.generateDdl}" />
                <property name="database" value="${jpa.database}" />
                <property name="showSql" value="${jpa.showSql}" />
            bean>
        property>
        
        
        
        <property name="jpaPropertyMap">
            <map>
                
                <entry key="javax.persistence.validation.mode" value="NONE" />
                
                <entry key="hibernate.query.startup_check" value="false" />
                
                <entry key="hibernate.query.substitutions" value="${hibernate.query.substitutions}" />
                
                <entry key="hibernate.default_batch_fetch_size" value="${hibernate.default_batch_fetch_size}" />
                
                <entry key="hibernate.max_fetch_depth" value="${hibernate.max_fetch_depth}" />
                
                <entry key="hibernate.generate_statistics" value="${hibernate.generate_statistics}" />
                
                <entry key="hibernate.bytecode.use_reflection_optimizer"
                    value="${hibernate.bytecode.use_reflection_optimizer}" />
                
                <entry key="hibernate.cache.use_second_level_cache" value="${hibernate.cache.use_second_level_cache}" />
                
                <entry key="hibernate.cache.use_query_cache" value="${hibernate.cache.use_query_cache}" />
                <entry key="hibernate.cache.region.factory_class" value="${hibernate.cache.region.factory_class}" />
                
                <entry key="net.sf.ehcache.configurationResourceName" value="${net.sf.ehcache.configurationResourceName}" />
                
                
                <entry key="hibernate.cache.use_structured_entries" value="${hibernate.cache.use_structured_entries}" />
            map>
        property>
    bean>

 

  

转载于:https://www.cnblogs.com/chrischris/p/7122392.html

你可能感兴趣的:(JPA entityManagerFactory配置详解)