1. 程式人生 > >spring-orm 和Hibernate整合

spring-orm 和Hibernate整合

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="net.shopxx.entity" />
        <property name="jpaVendorAdapter">// 指定orm實現為Hibernate
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />//開啟列印sql
                <property name="generateDdl" value="true" />
            </bean>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
                <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
                <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
                <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>
                <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
                <prop key="hibernate.connection.isolation">2</prop>
                <prop key="hibernate.connection.release_mode">on_close</prop>
                <prop key="javax.persistence.validation.mode">none</prop>
                <prop key="hibernate.search.analyzer">net.shopxx.AnsjAnalyzer</prop>
                <prop key="hibernate.search.default.directory_provider">filesystem</prop>
                <prop key="hibernate.search.default.indexBase">${java.io.tmpdir}/shopxx_index</prop>
                <prop key="hibernate.search.lucene_version">LUCENE_55</prop>
            </props>
        </property>
    </bean>