2

谁能告诉我如何使用 localhost 运行的 Google SQL Cloud 在 GAE 中解决此错误没有问题,但是当我部署到 GAE 时,它会显示此错误

javax.servlet.ServletContext 日志:分派传入 RPC 调用时出现异常 com.google.gwt.user.client.rpc.SerializationException:类型“org.hibernate.exception.SQLGrammarException”未包含在可以通过序列化的类型集中无法加载此 SerializationPolicy 或其 Class 对象。出于安全考虑,此类型不会被序列化。: instance = org.hibernate.exception.SQLGrammarException: could not execute query at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619 ) 在 com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.

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.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>
4

1 回答 1

0

据我所知,RPC 调用无法在 IOS 和 Andriod 等设备上运行。所以你最好避免使用 RPC 调用。

尝试使用 Ajax 请求从后面调用您的函数。在所有情况下都很顺利。

于 2012-09-12T03:22:26.217 回答