Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

java - JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()

Using hibernate in my application, and everytime I do a transaction, I get this warning. It is spamming my logs.

JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()

I think it is caused by hibernate.current_session_context_classproperty.

<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>

Is it something I should be worried about? If not, how can I stop the warning from appearing.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As far as I'm aware,it is not possible to configure Hibernate JPA with JTA support using Spring unless you provide a persistence.xml in order to configure the datasource as JTA. Perhaps some thing like this will help you get rid of the warning:

<?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>

I would also suggest you to disable allowLocalTransactions so that your code will run as transactional all the time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...