Reputation: 169
I am migrating my database from SQL Server to MySQL. I have setup the database, but when I configure it in the XML configuration file and execute the project, I get the following error:
java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
One more thing which is that all the select queries generated by Hibernate are executed successfully, but when Hibernate comes to execute the insert query the same exception is thrown.
In other words, it is unable to modify the database which is set up in MySQL.
This is my applicationcontext.xml code
<beans>
<!-- Hibernate -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test_live_30"/>
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="useTransactionAwareDataSource" value="true" />
<property name="mappingResources">
<list>
<value>src/dao/hbms/Company.hbm.xml</value>
<value>src/dao/hbms/ProductClaimsLoading.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="connection.pool_size">1</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
Upvotes: 0
Views: 8416
Reputation: 51
I know this post is old, but still this clue may help others.
I had similar issue when using Spring, Hibernate and a Spring Data repository, where in one of my AbstractRepository extends SimpleJPARepository
classes, I had to add the @Transactional
annotation to my customized methods. I found no solution/clue on Google or elsewhere. Somehow I identified this @Transactional
annotation is missing for new methods, once specified it started working like a charm.
Upvotes: 3