简体   繁体   English

为什么这个Hibernate MySQL连接是只读的?

[英]Why this Hibernate MySQL Connection is read-only?

I have an application using Spring with Hibernate on a MySQL database. 我有一个在MySQL数据库上使用Spring with Hibernate的应用程序。 For some reason, as of the last few days, anytime I try to persist any objects to my database I am getting the following error: 出于某种原因,从最近几天开始,每当我尝试将任何对象持久化到我的数据库时,我都会收到以下错误:

java.sql.SQLException: Connection is read-only. java.sql.SQLException:连接是只读的。 Queries leading to data modification are not allowed. 不允许导致数据修改的查询。 * *

I can't for the life of me figure out why this is happening. 我不能为我的生活弄清楚为什么会这样。 My application was working fine a few days ago. 几天前我的申请工作正常。

I am configuring a SessionFactory object in my applicationContext.xml file like this: 我正在我的applicationContext.xml文件中配置SessionFactory对象,如下所示:

     <bean id="sessionFactory" lass="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
         <property name="configLocation"
 value="classpath:/hibernate.cfg.xml"/>
         <property name="packagesToScan">
             <list>
                 <value>com.domain.domainObjects</value>
             </list>
         </property>
     </bean>

my hibernate.cfg.xml file looks like this: 我的hibernate.cfg.xml文件如下所示:

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://{url to db}:3306/{db name}</property>
        <property name="connection.username">{db user}</property>
        <property name="connection.password">{db password}</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">10</property>
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!-- Enable Hibernate's automatic session context management >
        <property name="current_session_context_class">thread</property-->
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>

    </session-factory>
</hibernate-configuration>

I am using a the mysql/j conenction version 5.1, hibernate version 3.2, spring mvc 3.0.5 我使用的是mysql / j conenction版本5.1,hibernate版本3.2,spring mvc 3.0.5

After about 3 hours of horrible debugging I now know what's going on. 经过大约3个小时的可怕调试后,我现在知道发生了什么。 I have a service-level method that I also have an "around" advice on. 我有一个服务级别的方法,我也有一个“周围”的建议。 The service-level method is annotated with @Transactional(readOnly=true) , however, I have another service in my advice that was annotated with @Transactional(readOnly=false) . 服务级别方法使用@Transactional(readOnly=true)注释,但是,我在我的建议中有另一个annotated with @Transactional(readOnly=false)服务annotated with @Transactional(readOnly=false)

My aspect (or advice) is using the same DAO objects as my normal service-layer, so when I called sessionFactory.getCurrenctSession() it's giving me back the session that was created for my Read-Only Service-level method. 我的方面(或建议)使用与我的普通服务层相同的DAO对象,所以当我调用sessionFactory.getCurrenctSession()它会返回为我的只读服务级方法创建的会话。 Now, I have to re-architect. 现在,我必须重新设计。

This looks like the bug they have in MySQL Connector/J for versions up to 5.1.6: http://bugs.mysql.com/bug.php?id=38747 这看起来像MySQL Connector / J中的版本高达5.1.6的版本: http//bugs.mysql.com/bug.php? id = 38747

Make sure that version is your case at least 5.1.7 确保版本至少是5.1.7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM