openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Persson (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (OPENJPA-2194) ReplicationDriver doesn't switch to write mode when using executeUpdate
Date Sat, 12 May 2012 23:20:48 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-2194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13274097#comment-13274097
] 

Daniel Persson commented on OPENJPA-2194:
-----------------------------------------

After some trial and error I came up with

em.getTransaction().begin();		
Query q = em.createQuery("delete from users");
OpenJPAEntityManager jem = OpenJPAPersistence.cast(em);
Connection c = (Connection) jem.getConnection();
c.setReadOnly(false);
q.executeUpdate();
c.setReadOnly(true);
em.getTransaction().commit();

Any better way to accomplice this?
                
> ReplicationDriver doesn't switch to write mode when using executeUpdate
> -----------------------------------------------------------------------
>
>                 Key: OPENJPA-2194
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2194
>             Project: OpenJPA
>          Issue Type: Bug
>            Reporter: Daniel Persson
>            Priority: Minor
>
> Usually the transaction commit is submitting the update and therefor handling the switch
to write mode. But in this case the switch never happens and exception is thrown.
> em.getTransaction().begin();		
> Query q = em.createQuery("delete from users");
> q.executeUpdate();
> em.getTransaction().commit();
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
> 	<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
> 		<class>org.ea.entities.User</class>
> 	    <properties>
> 	        <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/test"/>
> 	        <property name="openjpa.ConnectionUserName" value="root"/>
> 	        <property name="openjpa.ConnectionPassword" value="password"/>
> 	        <property name="openjpa.Log" value="DefaultLevel=INFO, Runtime=INFO, Tool=INFO,
SQL=INFO"/>
> 	        <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.ReplicationDriver"/>
  
> 	        <property name="openjpa.ConnectionFactoryProperties" value="autoReconnect=true,roundRobinLoadBalance=true"/>
  
> 	    </properties>
> 	</persistence-unit>
> </persistence>
> Exception in thread "main" <openjpa-2.2.0-r422266:1244990 fatal general error>
org.apache.openjpa.persistence.PersistenceException: Connection is read-only. Queries leading
to data modification are not allowed {prepstmnt 17578504 DELETE t0 FROM users t0} [code=0,
state=S1009]
> FailedObject: DELETE t0 FROM users t0 [java.lang.String]
> 	at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4918)
> 	at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4878)
> 	at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
> 	at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:78)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeBulkOperation(JDBCStoreQuery.java:579)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeDelete(JDBCStoreQuery.java:491)
> 	at org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeDelete(ExpressionStoreQuery.java:789)
> 	at org.apache.openjpa.kernel.QueryImpl.delete(QueryImpl.java:1025)
> 	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:822)
> 	at org.apache.openjpa.kernel.QueryImpl.deleteAll(QueryImpl.java:888)
> 	at org.apache.openjpa.kernel.QueryImpl.deleteAll(QueryImpl.java:884)
> 	at org.apache.openjpa.kernel.DelegatingQuery.deleteAll(DelegatingQuery.java:558)
> 	at org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:374)
> 	at org.ea.test.TestAdd.main(TestAdd.java:49)
> Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Connection is read-only.
Queries leading to data modification are not allowed {prepstmnt 17578504 DELETE t0 FROM users
t0} [code=0, state=S1009]
> 	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:247)
> 	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:223)
> 	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$1000(LoggingConnectionDecorator.java:72)
> 	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1162)
> 	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:272)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1741)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeUpdate(JDBCStoreQuery.java:746)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeBulkOperation(JDBCStoreQuery.java:577)
> 	... 9 more
> NestedThrowables:
> java.sql.SQLException: Connection is read-only. Queries leading to data modification
are not allowed
> 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
> 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
> 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
> 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
> 	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2395)
> 	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
> 	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2347)
> 	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
> 	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
> 	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:272)
> 	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1160)
> 	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:272)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1741)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeUpdate(JDBCStoreQuery.java:746)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeBulkOperation(JDBCStoreQuery.java:577)
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeDelete(JDBCStoreQuery.java:491)
> 	at org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeDelete(ExpressionStoreQuery.java:789)
> 	at org.apache.openjpa.kernel.QueryImpl.delete(QueryImpl.java:1025)
> 	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:822)
> 	at org.apache.openjpa.kernel.QueryImpl.deleteAll(QueryImpl.java:888)
> 	at org.apache.openjpa.kernel.QueryImpl.deleteAll(QueryImpl.java:884)
> 	at org.apache.openjpa.kernel.DelegatingQuery.deleteAll(DelegatingQuery.java:558)
> 	at org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:374)
> 	at org.ea.test.TestAdd.main(TestAdd.java:49)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message