나는 MySQL 데이터베이스에서 Hibernate와 Spring을 사용하는 애플리케이션을 가지고있다. 이런 일이 왜왜이 Hibernate MySQL Connection은 읽기 전용입니까?
java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed.*
나는 내 인생을 알아낼 수 없습니다 위해 : 어떤 이유로, 지난 몇 일의로, 언제 나는 다음과 같은 오류가 점점 오전 내 데이터베이스에 대한 모든 오브젝트를 지속하려고 . 며칠 전 제 신청서가 정상적으로 작동했습니다.
나는이처럼 내 applicationContext.xml 파일에 SessionFactory에 객체를 구성하고있다 : 나는 MySQL을 사용하고
<?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>
을 :
는 <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 파일은 다음과 같다/j conenction version 5.1, hibernate version 3.2, spring mvc 3.0.5
구성이 양호합니다. 이 문제의 영향을받는 샘플 코드도 추가하십시오. 또한 MySQL 드라이버의 정확한 버전을 지정할 수 있다면 좋을 것입니다. – jpkrohling
Transactional 주석을 사용하고 있습니까? @Transactional로 설정되어 있습니까 (readOnly = true) –
약 3 시간 동안 끔찍한 디버깅을 한 후, 지금 무슨 일이 벌어지고 있는지 알게되었습니다. 나는 또한 "주위에"충고가있는 서비스 수준 방법이 있습니다. 서비스 수준 메서드는 @Transactional (readOnly = true)으로 주석 처리되어 있지만, @Transactional (readOnly = false) 주석이 달린 조언이있는 다른 서비스가 있습니다. 내 aspect (또는 advice)는 보통의 service-layer와 같은 DAO 객체를 사용하기 때문에 sessionFactory.getCurrenctSession()을 호출하면 읽기 전용 서비스 레벨 메소드를 위해 만들어진 세션을 다시 돌려 준다. 이제 다시 건축해야합니다. 귀하의 답변에 감사드립니다! –