JTASessionContext与JDBCTransactionFactory一起使用;自动刷新将无法正确使用getCurrentSession() [英] JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()

查看:80
本文介绍了JTASessionContext与JDBCTransactionFactory一起使用;自动刷新将无法正确使用getCurrentSession()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中使用hibernate,并且每次执行事务时,都会收到此警告。它是垃圾邮件我的日志。

  JTASessionContext与JDBCTransactionFactory一起使用;自动刷新将无法正确使用getCurrentSession()

我认为它是由<$ c $造成的C>的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.0xmlns =http://java.sun.com/xml/ns/persistencexmlns:xsi =http://www.w3.org/2001/XMLSchema-实例xsi:schemaLocation =http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd\">
< persistence-unit name =somethingtransaction-type =JTA>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
< jta-data-source>等等等等< / jta-data-source>
<属性>
< property name =hibernate.archive.autodetectionvalue =class/>
< property name =hibernate.cache.provider_classvalue =org.hibernate.cache.NoCacheProvider/>
< property name =hibernate.hbm2ddl.autovalue =update/>
< property name =hibernate.current_session_context_classvalue =jta/>
< property name =hibernate.transaction.manager_lookup_classvalue =blah blah/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.SQLServerDialect/>
< property name =hibernate.connection.release_modevalue =after_statement/>
< / properties>
< / persistence-unit>
< /余辉>

我还建议您禁用 allowLocalTransactions ,以便代码运行作为交易始终。


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.

解决方案

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.

这篇关于JTASessionContext与JDBCTransactionFactory一起使用;自动刷新将无法正确使用getCurrentSession()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆