为什么这个Hibernate MySQL Connection是只读的? [英] Why this Hibernate MySQL Connection is read-only?

查看:37
本文介绍了为什么这个Hibernate MySQL Connection是只读的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL数据库上有一个使用Spring和Hibernate的应用程序.由于某些原因,从最近几天开始,每当我尝试将任何对象持久保存到数据库中时,都会出现以下错误:

I have an application using Spring with Hibernate on a MySQL database. 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:连接是只读的.导致数据修改的查询是不允许. *

我无法为自己的生活弄清楚为什么会这样.我的应用程序几天前运行良好.

I can't for the life of me figure out why this is happening. My application was working fine a few days ago.

我正在像这样在我的applicationContext.xml文件中配置SessionFactory对象:

I am configuring a SessionFactory object in my applicationContext.xml file like this:

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

我的hibernate.cfg.xml文件如下所示:

my hibernate.cfg.xml file looks like this:

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

我正在使用mysql/j conenction版本5.1,hibernate版本3.2,spring mvc 3.0.5

I am using a the mysql/j conenction version 5.1, hibernate version 3.2, spring mvc 3.0.5

推荐答案

经过大约3个小时的可怕调试,我现在知道发生了什么.我有一个服务级别的方法,也有一个关于"建议.服务级别的方法以 @Transactional(readOnly = true)进行注释,但是,我的建议中还有另一项服务以 @Transactional(readOnly = false)进行了注释..

After about 3 hours of horrible debugging I now know what's going on. 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).

我的方面(或建议)使用的是与正常服务层相同的DAO对象,因此当我调用 sessionFactory.getCurrenctSession()时,它将回传为我的Read创建的会话-仅服务级别的方法.现在,我必须重新架构.

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. Now, I have to re-architect.

这篇关于为什么这个Hibernate MySQL Connection是只读的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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