弹出hibernate配置默认使用resource_local或jta?

时间:2009-12-27 03:24:25

标签: java hibernate spring persistence jta

我可能知道我的配置是直接在applicationContext.xml上完成的,我没有persistence.xml。默认情况下这是resource_loca还是jta?如果我想使用jta,我需要添加额外的参数吗?

<bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>oracle.jdbc.driver.OracleDriver</value>
        </property>
            <!-- xdb is defined by running the hsqldb as xdb (see above) -->
        <property name="url">
            <value>jdbc:oracle:thin:@theserver:1521:appsdb</value>
        </property>
        <property name="username">
            <value>test</value>
        </property>
        <property name="password">
            <value>test</value>
        </property>
    </bean>




<bean id="annotatedsessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">


    <property name="packagesToScan" value="com.company.x.model" >
    </property>


    <property name="hibernateProperties">
        <props>

            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.use_sql_comments">true</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">20</prop>
            <prop key="hibernate.c3p0.timeout">1800</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>
            <prop key="hibernate.cache.provider_class">
                  com.company.x.services.ExternalEhCacheProvider
            </prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>



        </props>
    </property>
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>

</bean>

1 个答案:

答案 0 :(得分:4)

RESOURCE_LOCAL仅适用于JPA EntityManager,而不适用于Hibernate SessionFactory。 Hibernate的Spring集成比使用JPA更平滑,因此决定事务行为的唯一因素是您使用它的事务管理器(HibernateTransactionManagerJtaTransactionManager)。它可以与任何一个一起使用,而无需您明确配置SessionFactory