[英]Why this Hibernate MySQL Connection is read-only?
我有一個在MySQL數據庫上使用Spring with Hibernate的應用程序。 出於某種原因,從最近幾天開始,每當我嘗試將任何對象持久化到我的數據庫時,我都會收到以下錯誤:
java.sql.SQLException:連接是只讀的。 不允許導致數據修改的查詢。 *
我不能為我的生活弄清楚為什么會這樣。 幾天前我的申請工作正常。
我正在我的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>
我的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>
我使用的是mysql / j conenction版本5.1,hibernate版本3.2,spring mvc 3.0.5
經過大約3個小時的可怕調試后,我現在知道發生了什么。 我有一個服務級別的方法,我也有一個“周圍”的建議。 服務級別方法使用@Transactional(readOnly=true)
注釋,但是,我在我的建議中有另一個annotated with @Transactional(readOnly=false)
服務annotated with @Transactional(readOnly=false)
。
我的方面(或建議)使用與我的普通服務層相同的DAO對象,所以當我調用sessionFactory.getCurrenctSession()
它會返回為我的只讀服務級方法創建的會話。 現在,我必須重新設計。
這看起來像MySQL Connector / J中的版本高達5.1.6的版本: http : //bugs.mysql.com/bug.php? id = 38747
確保版本至少是5.1.7
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.