在应用程序中使用hibernate模式,每次执行事务时,都会收到此警告。它在滥发我的日志。
JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
我认为这是hibernate.current_session_context_class财产造成的。
hibernate.current_session_context_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>
我应该担心吗?如果没有,我该如何阻止警告出现。
据我所知,除非您提供persistence.xml以便将数据源配置为JTA,否则无法使用Spring来配置具有JTA支持的Hibernate JPA。也许这样的事情可以帮助您摆脱警告:
<?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>
我还建议您禁用 allowLocalTransactions, 以便您的代码 始终 以事务性方式运行。