Handling sql restarts with guice persist

61 views
Skip to first unread message

David Roberts

unread,
Aug 3, 2016, 5:08:10 AM8/3/16
to google-guice
So I have noticed that when cloud sql has a maintenance window my app seems to die as the entity manager does not seem to be able to handle the sql restarts and I need to go into appengine and restart the app.

I can also replicate this on my local using mysql and stopping/starting.

I am using the normal setup from the instructions in the docs and running inside appengine along with https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory
public class MyModule extends ServletModule {
 
protected void configureServlets() {
    install
(new JpaPersistModule("MyApp"));  // like we saw earlier.

    filter
("/*").through(PersistFilter.class);
 
}
}

persistence.xml looks like

<?xml version="1.0" encoding="UTF-8"?>
<persistence
        version="2.0">

    <!--Define Persistence Unit for the application-->
    <persistence-unit name="MyApp" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>myapp.persistence.sql.entity.TestObject</class>

        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://google/myapp?cloudSqlInstance=myapp-instance:us-east1:myapp&socketFactory=com.google.cloud.sql.mysql.SocketFactory" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="password" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.connection.useUnicode" value="true" />
            <property name="hibernate.connection.characterEncoding" value="UTF-8" />
            <property name="validationQuery" value="SELECT 1" />
            <property name="testOnBorrow" value="true" />
        </properties>
    </persistence-unit>
</persistence>


A few posts said to try using the validationQuery and testOnBorrow but this definately doesnt work, I also tried using c3po settings 

<property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.min_size" value="0" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.idle_test_period" value="300" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.timeout" value="100" />
<property name="hibernate.c3p0.preferredTestQuery" value="SELECT 1" />

But when I try to run I get the error 

java.lang.NoClassDefFoundError: java.lang.management.ManagementFactory is a restricted class. Please see the Google  App Engine developer's guide for more details

Am I missing something obvious or do I need to something myself to handle the restarts?

Any advice appreciated, thanks.

Reply all
Reply to author
Forward
0 new messages