有人能告诉我如何使用Google SQL Cloud在GAE中解决此错误 我使用localhost运行没问题但是当我部署到GAE时它会显示此错误
javax.servlet.ServletContext log:调度传入的RPC调用时发生异常 com.google.gwt.user.client.rpc.SerializationException:类型'org.hibernate.exception.SQLGrammarException'未包含在可由此SerializationPolicy序列化的类型集中,或者无法加载其Class对象。出于安全考虑,此类型不会被序列化:instance = org.hibernate.exception.SQLGrammarException:无法执行查询 在com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619) 在com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126) 在com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter $ ValueWriter $ 8.write(ServerSerializationStreamWriter.java:153) 在com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:539) 在com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616) 在com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:390) 在com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:368) 在net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:205) 在com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248) 在com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 在org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1166) 在com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102) 在org.mortbay.jetty.servlet.ServletHandler $ CachedChain.doFilter(ServletHandler.java:1157) 在com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35) 在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) 在org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 在org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 在org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 在com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:249) 在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) at org.mortbay.jetty.HttpConnection $ RequestHandler.headerComplete(HttpConnection.java:923) 在com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76) 在org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 在com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135) 在com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.run(JavaRuntime.java:447) 在com.google.tracing.TraceContext $ TraceContextRunnable.runInContext(TraceContext.java:452) 在com.google.tracing.TraceContext $ TraceContextRunnable $ 1.run(TraceContext.java:458) 在com.google.tracing.TraceContext.runInContext(TraceContext.java:698) 在com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:336) 在com.google.tracing.TraceContext $ AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:328) 在com.google.tracing.TraceContext $ TraceContextRunnable.run(TraceContext.java:456) 在com.google.apphosting.runtime.ThreadGroupPool $ PoolEntry.run(ThreadGroupPool.java:251) 在java.lang.Thread.run(Thread.java:679)
Hibernate Util的这段代码
package com.ies.ieschool.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSession() {
return sessionFactory;
}
}
这是DTO的一个
package com.ies.ieschool.shared;
// Generated 31 �.�. 2555, 1:54:03 by Hibernate Tools 3.4.0.CR1
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import net.sf.gilead.pojo.gwt.LightEntity;
/**
* Province generated by hbm2java
*/
@Entity
@Table(name = "province", catalog = "ieschool")
public class Province extends LightEntity implements Serializable {
private static final long serialVersionUID = 1L;
private short provinceId;
private Geography geography;
private String provinceCode;
private String provinceName;
private Set<Father> fathers;
private Set<Mother> mothers;
private Set<Student> studentsForAddressProvince;
private Set<Student> studentsForAddressCensusProvince;
private Set<Student> studentsForGraduatedSchoolProvince;
private Set<Student> studentsForBirthAddressProvince;
private Set<City> cities;
private Set<ExperienceWork> experienceWorks;
private Set<District> districts;
private Set<Guardian> guardians;
private Set<Postcode> postcodes;
private Set<Personal> personalsForAddressProvince;
private Set<SeminarProfile> seminarProfiles;
private Set<Personal> personalsForLicenseIssueProvince;
public Province() {
}
@Id
@Column(name = "province_id", unique = true, nullable = false)
public short getProvinceId() {
return this.provinceId;
}
public void setProvinceId(short provinceId) {
this.provinceId = provinceId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "geography_id", nullable = false)
public Geography getGeography() {
return this.geography;
}
public void setGeography(Geography geography) {
this.geography = geography;
}
@Column(name = "province_code", nullable = false, length = 2)
public String getProvinceCode() {
return this.provinceCode;
}
public void setProvinceCode(String provinceCode) {
this.provinceCode = provinceCode;
}
@Column(name = "province_name", nullable = false, length = 150)
public String getProvinceName() {
return this.provinceName;
}
public void setProvinceName(String provinceName) {
this.provinceName = provinceName;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<Father> getFathers() {
return this.fathers;
}
public void setFathers(Set<Father> fathers) {
this.fathers = fathers;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<Mother> getMothers() {
return this.mothers;
}
public void setMothers(Set<Mother> mothers) {
this.mothers = mothers;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "provinceByAddressProvince")
public Set<Student> getStudentsForAddressProvince() {
return this.studentsForAddressProvince;
}
public void setStudentsForAddressProvince(Set<Student> studentsForAddressProvince) {
this.studentsForAddressProvince = studentsForAddressProvince;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "provinceByAddressCensusProvince")
public Set<Student> getStudentsForAddressCensusProvince() {
return this.studentsForAddressCensusProvince;
}
public void setStudentsForAddressCensusProvince(
Set<Student> studentsForAddressCensusProvince) {
this.studentsForAddressCensusProvince = studentsForAddressCensusProvince;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "provinceByGraduatedSchoolProvince")
public Set<Student> getStudentsForGraduatedSchoolProvince() {
return this.studentsForGraduatedSchoolProvince;
}
public void setStudentsForGraduatedSchoolProvince(
Set<Student> studentsForGraduatedSchoolProvince) {
this.studentsForGraduatedSchoolProvince = studentsForGraduatedSchoolProvince;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "provinceByBirthAddressProvince")
public Set<Student> getStudentsForBirthAddressProvince() {
return this.studentsForBirthAddressProvince;
}
public void setStudentsForBirthAddressProvince(
Set<Student> studentsForBirthAddressProvince) {
this.studentsForBirthAddressProvince = studentsForBirthAddressProvince;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<City> getCities() {
return this.cities;
}
public void setCities(Set<City> cities) {
this.cities = cities;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<ExperienceWork> getExperienceWorks() {
return this.experienceWorks;
}
public void setExperienceWorks(Set<ExperienceWork> experienceWorks) {
this.experienceWorks = experienceWorks;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<District> getDistricts() {
return this.districts;
}
public void setDistricts(Set<District> districts) {
this.districts = districts;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<Guardian> getGuardians() {
return this.guardians;
}
public void setGuardians(Set<Guardian> guardians) {
this.guardians = guardians;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<Postcode> getPostcodes() {
return this.postcodes;
}
public void setPostcodes(Set<Postcode> postcodes) {
this.postcodes = postcodes;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "provinceByAddressProvince")
public Set<Personal> getPersonalsForAddressProvince() {
return this.personalsForAddressProvince;
}
public void setPersonalsForAddressProvince(Set<Personal> personalsForAddressProvince) {
this.personalsForAddressProvince = personalsForAddressProvince;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "province")
public Set<SeminarProfile> getSeminarProfiles() {
return this.seminarProfiles;
}
public void setSeminarProfiles(Set<SeminarProfile> seminarProfiles) {
this.seminarProfiles = seminarProfiles;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "provinceByLicenseIssueProvince")
public Set<Personal> getPersonalsForLicenseIssueProvince() {
return this.personalsForLicenseIssueProvince;
}
public void setPersonalsForLicenseIssueProvince(
Set<Personal> personalsForLicenseIssueProvince) {
this.personalsForLicenseIssueProvince = personalsForLicenseIssueProvince;
}
}
这个为DAO
package com.ies.ieschool.server;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import com.ies.ieschool.client.service.ProvinceService;
import com.ies.ieschool.shared.Province;
import net.sf.gilead.core.PersistentBeanManager;
import net.sf.gilead.core.hibernate.HibernateUtil;
import net.sf.gilead.core.serialization.GwtProxySerialization;
import net.sf.gilead.core.store.stateless.StatelessProxyStore;
import net.sf.gilead.gwt.PersistentRemoteService;
@SuppressWarnings("serial")
public class ProvinceImpl extends PersistentRemoteService implements ProvinceService{
public ProvinceImpl() {
HibernateUtil hibernateUtil = new HibernateUtil();
hibernateUtil.setSessionFactory(com.ies.ieschool.util.HibernateUtil.getSession());
PersistentBeanManager persistentBeanManager = new PersistentBeanManager();
persistentBeanManager.setPersistenceUtil(hibernateUtil);
StatelessProxyStore sps = new StatelessProxyStore();
sps.setProxySerializer(new GwtProxySerialization());
persistentBeanManager.setProxyStore(sps);
setBeanManager(persistentBeanManager);
}
@Override
public Province findProvinceByPK(int provinceId) throws Exception {
Province province;
Session session = com.ies.ieschool.util.HibernateUtil.getSession().getCurrentSession();
session.beginTransaction();
province = (Province) session.createQuery("SELECT new Province( " +
"pvn.provinceId, " +
"pvn.provinceName " +
") " +
"FROM Province pvn " +
"WHERE pvn.provinceId = :id " +
"ORDER BY pvn.provinceName").setInteger("id", provinceId).uniqueResult();
session.getTransaction().commit();
return province;
}
@Override
public List<Province> findAllProvince() throws Exception {
List<Province> list = null;
Session session = com.ies.ieschool.util.HibernateUtil.getSession().getCurrentSession();
session.beginTransaction();
list = new ArrayList<Province> (session.createQuery("SELECT new Province( " +
"pvn.provinceId, " +
"pvn.provinceName " +
") " +
"FROM Province pvn " +
"ORDER BY pvn.provinceName").list());
session.getTransaction().commit();
return list;
}
}
这个用于hibernate映射(hibernate.cfg.xml)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.google.appengine.api.rdbms.AppEngineDriver</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.url">jdbc:google:rdbms://ies-thamvitya-db:ieschool/ieschool_rif</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">1</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="javax.persistence.validation.mode">none</property>
<mapping class="com.ies.ieschool.shared.Province" />
</session-factory>
</hibernate-configuration>
答案 0 :(得分:0)
据我所知,RPC调用无法在IOS和Andriod等设备上运行。所以你最好避免使用RPC调用。
尝试使用Ajax请求从后面调用您的函数。它在所有情况下都很顺利。