GAE - 使用Google Cloud SQL的Google端点

时间:2020-12-26 23:13:08

I've tried integrate de Endpoints with Cloud SQL and Hibernate. But, everytime a have a error. Follow my tests:

我尝试将de Endpoints与Cloud SQL和Hibernate集成。但是,每次都有错误。按照我的测试:

1 - persistence.xml in source folder: http://imgur.com/hKjf8Cs Give-me the error: http://imgur.com/QJe8rvq

1 - 源文件夹中的persistence.xml:http://imgur.com/hKjf8Cs给我错误:http://imgur.com/QJe8rvq

2 - persistence.xml in resources folder give me the error:

2 - resources文件夹中的persistence.xml给出了错误:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named gegAdminPU at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) at br.com.gegsystems.gegadmin.utils.HibernateUtils.(HibernateUtils.java:47) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:188) at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70) at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64) at br.com.gegsystems.gegadmin.endpoints.ClienteEndpoint.(ClienteEndpoint.java:20) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:266) at com.google.api.server.spi.ServletInitializationParameters.getClassForName(ServletInitializationParameters.java:82) at com.google.api.server.spi.ServletInitializationParameters.fromServletConfig(ServletInitializationParameters.java:51) at com.google.api.server.spi.SystemServiceServlet.init(SystemServiceServlet.java:102) at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440) at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366) at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349) at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

javax.persistence.PersistenceException:否EntityManager的持久性提供者在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)在br.com.gegsystems.gegadmin.utils.HibernateUtils命名gegAdminPU(HibernateUtils.java:47)在爪哇。 .lang.Class.forName0(本地方法)在java.lang.Class.forName(Class.java:188)在com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)在com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:64)在br.com.gegsystems.gegadmin.endpoints.ClienteEndpoint。(ClienteEndpoint.java:20)在java.lang中。 Class.forName0(本地方法)在java.lang.Class.forName(Class.java:266)在com.google.api.server.spi.ServletInitializationParameters.getClassForName(ServletInitializationParameters.java:82)在com.google.api。 com.google.api.server.spi.SystemServiceServ上的server.spi.ServletInitializationParameters.fromServletConfig(ServletInitializationParameters.java:51) let.init(SystemServiceServlet.java:102)在org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)在org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)在组织.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1166)在com.google.appengine.api.socket.dev .DevSocketFilter.doFilter(DevSocketFilter.java:74)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)在com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java :127)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)在com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)在org.mortbay。 com.google.appengine.api.blobstore.dev.ServeBlobFilter.d中的jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157) oFilter(ServeBlobFilter.java:63)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)在com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)在com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)在org.mortbay.jetty.servlet .ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)位于com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter)的.java:349)在com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157)的组织。 mortbay.jetty.servlet.ServletHandle r.handle(ServletHandler.java:388)在org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)在组织.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)在com.google.appengine.tools.development.DevAppEngineWebAppContext.handle (DevAppEngineWebAppContext.java:98)在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)在com.google.appengine.tools.development.JettyContainerService $ ApiProxyHandler.handle(JettyContainerService.java:491)在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)在org.mortbay.jetty.Server.handle(Server.java:326)在org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java: 542)在org.mortbay.jetty.HttpConnection $ RequestHandler.content(HttpConnection.java:938)在org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)的组织。 mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)在org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)在org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)在org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:582)

Follow the Endpoint code and HibernateUtils:

遵循端点代码和HibernateUtils:

@Api(name="clientes", version="v1")
public class ClienteEndpoint {

private static EntityManagerFactory entityManagerFactory;

static {
    entityManagerFactory = HibernateUtils.getEntityManagerFactory();
}

@ApiMethod(name="listar", path="clientes")
public List<String> listar(){
    List<String> resultado = new ArrayList<String>();
    EntityManager em = entityManagerFactory.createEntityManager();

    em.getTransaction().begin();

    resultado.add((String) em.createQuery("SELECT 'teste' FROM dual;").getSingleResult());

    return resultado;
}

}



public class HibernateUtils {

private static final EntityManagerFactory entityManagerFactory;

public static EntityManagerFactory getEntityManagerFactory(){
    return entityManagerFactory;
}

static {
    try {
        DriverManager.registerDriver(new AppEngineDriver());            
    }catch(SQLException e){
        throw new ExceptionInInitializerError(e);
    }

    Map<String, String> properties = new HashMap();
    if (SystemProperty.environment.value() ==
          SystemProperty.Environment.Value.Production) {
      properties.put("javax.persistence.jdbc.driver",
          "com.mysql.jdbc.GoogleDriver");
      properties.put("javax.persistence.jdbc.url",
          System.getProperty("jdbc:google:mysql://**********:*******/gegadmin?user=root"));
      properties.put("javax.persistence.jdbc.password",
              System.getProperty("**********"));
    } else {
      properties.put("hibernate.connection.driver_class",
          "com.mysql.jdbc.Driver");
      properties.put("hibernate.connection.url",
          System.getProperty("jdbc:mysql://localhost:3306/gegadmin?user=root"));
      properties.put("hibernate.connection.password",
              System.getProperty("**********"));
    }

    entityManagerFactory = Persistence.createEntityManagerFactory("gegAdminPU", properties);
}

}

1 个解决方案

#1


0  

I've changed the persistence framework from Hibernate to EclipseLink and work. I think that was a problem in the configuration of my Eclipse with Hibernate and JPA.

我已经将持久性框架从Hibernate更改为EclipseLink并且工作正常。我认为这是我的Eclipse配置Hibernate和JPA的一个问题。

#1


0  

I've changed the persistence framework from Hibernate to EclipseLink and work. I think that was a problem in the configuration of my Eclipse with Hibernate and JPA.

我已经将持久性框架从Hibernate更改为EclipseLink并且工作正常。我认为这是我的Eclipse配置Hibernate和JPA的一个问题。