我試過將端點與雲端SQL和休眠集成在一起。 但是,每次出現錯誤。 按照我的測試:GAE - 谷歌端點與Google雲端SQL
1 - persistence.xml中的源文件夾: http://imgur.com/hKjf8Cs 給,我的錯誤: http://imgur.com/QJe8rvq
2 - 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)
按照端點代碼和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);
}
}
我有一個問題,其中System.getProperty(「whatever」)從端點堆棧調用時返回null,但它在通過servlet調用時會起作用;我不知道它是否有關,但可能值得檢查 –
感謝您的回答。我已經將持久性框架從Hibernate更改爲EclipseLink並且可以工作。我認爲這是使用Hibernate和JPA配置Eclipse的問題。 –