使用Spring和Hibernate时出现Google App Engine错误

时间:2014-03-18 02:08:30

标签: spring hibernate google-app-engine

我正在使用Spring 2.0和hibernate,但是当我尝试将应用程序移植到GAE时,我遇到了以下错误。

javax.servlet.ServletContext log: Exception while dispatching incoming RPC call com.google.gwt.user.client.rpc.SerializationException: 
        Type 'org.springframework.beans.factory.BeanCreationException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. 
        For security purposes, this type will not be serialized.:
        instance = org.springframework.beans.factory.BeanCreationException: 
        Error creating bean with name 'ManagerAdmin' defined in class path resource [applicationContext.xml]: 
        Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';
    nested exception is org.springframework.beans.factory.BeanCreationException: 
        Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: 
        Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; 
    nested exception is org.springframework.beans.factory.BeanCreationException: 
        Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]:
        Error setting property values; 
    nested exception is org.springframework.beans.NotWritablePropertyException: 
        Invalid property 'hibernate.dialect' of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: 
        Nested property in path 'hibernate.dialect' does not exist; 
    nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'hibernate' of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: 
        Bean property 'hibernate' is not readable or has an invalid getter method: 
        Does the return type of the getter match the parameter type of the setter

这是我正在使用的application.xml:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="driverClassName" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
<property name="url" value="jdbc:google:rdbms://cloudsql/XXXXX:XXXX/XXXXdb?user=XXXX" />
<property name="username" value="XXXXX" />
<property name="password" value="XXXXX" />

感谢任何帮助。

由于

拉​​加。

按照Ean的说法,建议更正applicationContext.xml。我现在得到以下错误。

javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'org.hibernate.exception.DataException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = org.hibernate.exception.DataException: Cannot open connection
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:665)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:153)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:585)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:755)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:794)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:667)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:153)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:585)
    at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:605)
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:393)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    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 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.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
    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.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:724)

1 个答案:

答案 0 :(得分:1)

hibernate.dialect是一个Hibernate属性,应该传递给sessionFactory。您将它传递给不知道此类属性的dataSource bean。以下是您应该做的事情的样本:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.google.appengine.api.rdbms.AppEngineDriver"/>
    <property name="url" value="jdbc:google:rdbms://cloudsql/XXXXX:XXXX/XXXXdb?user=XXXX" />
    <property name="username" value="XXXXX" />
    <property name="password" value="XXXXX" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.project.EntityClass</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>     
            </props>
        </property>
    </bean>

注意hibernate.dialect的传递方式。