Java 与JDBCTransactionFactory一起使用的JTASessionContext;使用getCurrentSession()自动刷新将无法正常运行

Java 与JDBCTransactionFactory一起使用的JTASessionContext;使用getCurrentSession()自动刷新将无法正常运行,java,hibernate,jdbc,jta,Java,Hibernate,Jdbc,Jta,在我的应用程序中使用hibernate,每次执行事务时,都会收到此警告。它在滥发我的日志 JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession() 我认为这是由hibernate.current\u session\u context\u class属性引起的 <hibernate-configuratio

在我的应用程序中使用hibernate,每次执行事务时,都会收到此警告。它在滥发我的日志

JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
我认为这是由hibernate.current\u session\u context\u class属性引起的

<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
    <property name="hibernate.connection.pool_size">5</property>
    <property name="show_sql">false</property>
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="hibernate.current_session_context_class">jta</property>

    <mapping class="foo.bar.Class1" />
    <mapping class="foo.bar.Class2" />
    <mapping class="foo.bar.Class3" />
    <mapping class="foo.bar.Class4" />
    <mapping class="foo.bar.Class5" />
</session-factory>

net.sourceforge.jtds.jdbc.Driver
5.
假的
org.hibernate.dialogue.sqlserverdialogue
jta


这是我应该担心的事情吗?如果没有,如何阻止警告出现。

据我所知,除非您提供persistence.xml以将数据源配置为JTA,否则无法使用Spring将Hibernate JPA配置为JTA支持。 也许这样的事情可以帮助你摆脱警告:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="something" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>blah blah</jta-data-source>
        <properties>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.current_session_context_class" value="jta"/>
            <property name="hibernate.transaction.manager_lookup_class" value="blah blah"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>          
            <property name="hibernate.connection.release_mode" value="after_statement"/>
        </properties>
    </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
废话

我还建议您禁用allowLocaltTransactions,这样您的代码将始终作为事务运行。

需要查看您完成的hibernate配置文件或完整的标记…@DarkHorse:当然,更新的初始问题如何加载配置我的项目以从
persistence.xml
加载内容?我想您的applicationContext中已经有一个“entityManager”bean。然后添加以下属性:。你可以把persistence.xml放在像你的META-INFNo这样的地方。applicationContext
Spring
不是吗?我错了,我以为您在使用Spring框架:),所以只需用上面的xml替换您的hibernate配置。当然,添加必要的属性。当我使用旧的hibernate cfg时,对于每个文件,我都必须像原始帖子一样提供映射,我如何在persistence.xml中这样做?