openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rob Scala <rsc...@buyersedgepurchasing.com>
Subject TableGenerator and Replication
Date Mon, 02 Nov 2015 21:16:21 GMT
Hello,

I am testing replication using JPA and mysql.  It's really sweet how it 
automatically goes to the primary database for every write transaction.

The problem is when I try to persist an entity using a TableGenerator, 
it fails with this message:

      Cannot execute statement in a READ ONLY transaction.
     {prepstmnt 1880527972 SELECT ID FROM insidetrack.id_generator WHERE 
TYPE0 = ? FOR UPDATE} [code=1792, state=25006]

Here's my connection information:

     openjpa.ConnectionDriverName=com.mysql.jdbc.ReplicationDriver
openjpa.ConnectionURL=jdbc:mysql:replication://192.168.1.35:3306,192.168.1.52:3306/insidetrack

And here is the code:

@Entity
@Table(name="rebate_agreement")
public class RebateAgreement implements NamedObject, DocumentOwner, 
SignedNotesHolder
{
     @TableGenerator(name="RebateGenerator",
             table="id_generator",
             pkColumnName="TYPE",
             pkColumnValue="REBATE",
             valueColumnName="ID",
             initialValue=10001,
             allocationSize=1)
     @Id @GeneratedValue(strategy=GenerationType.TABLE, 
generator="RebateGenerator")
     private long id;

     @Version
     private int version;

     private String name;
     // etc.
}

The prepared statement from the error message indicates that when it 
tries to get an ID using the TableGenerator, the connection is read-only 
causing it to use the slave database.

Does anyone have any insights?

Thank you,

Rob


-- 
*Rob Scala*
Director of Information Technology
Buyers Edge, Inc
351 N. Frontage Road, Suite A210
New London, CT 06320
Phone - 860-701-0538x27
Fax - 860-701-0576

Mime
View raw message