0

我对 GW 和 Hibernate 有疑问。

在我的数据库中,我有一个表和一个Sinav(Exam)名为. 当我想使用 Hibernate 从数据库中访问考试列表时,会发生错误。Soru(Question)sinav_soru(Exam_Question)

这是错误详细信息

   [WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'org.hibernate.collection.PersistentBag' 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 = [tr.edu.gsu.yds.shared.domain.Soru@307262ee]
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:619)
    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:539)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:709)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:748)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:621)
    at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
    at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:44)
    at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:39)
    at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:51)
    at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:28)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:740)
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:621)
    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:539)
    at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616)
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:474)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:571)
    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:487)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

真的我无法解决问题。

这是我的域代码如下:

Sinav.java(考试)

package tr.edu.gsu.yds.shared.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "sinav")
public class Sinav implements Serializable
{
    private static final long serialVersionUID = 1L;

    private Integer sinavId;
    private String sinavAd;
    private String eklenmeTarihi;
    private Ogretmen ogretmen;
    private List<Ogrenci> ogrenciler = new ArrayList<Ogrenci>();
    private List<Soru> sorular = new ArrayList<Soru>();

    @Id
    @GeneratedValue( strategy=GenerationType.IDENTITY )
    @Column(name = "sinavId", length=10)
    public Integer getSinavId() {
        return sinavId;
    }

    public void setSinavId(Integer sinavId) {
        this.sinavId = sinavId;
    }

    @Column(name = "sinavAd", nullable = false)
    public String getSinavAd() {
        return sinavAd;
    }

    public void setSinavAd(String sinavAd) {
        this.sinavAd = sinavAd;
    }

    @Column(name = "eklenmeTarihi", nullable = false)
    public String getEklenmeTarihi() {
        return eklenmeTarihi;
    }


    public void setEklenmeTarihi(String eklenmeTarihi) {
        this.eklenmeTarihi = eklenmeTarihi;
    }



    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "ogretmenNo")
    public Ogretmen getOgretmen() {
        return this.ogretmen;
    }

    public void setOgretmen(Ogretmen ogretmen) {
        this.ogretmen = ogretmen;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "sinav")
    public List<Ogrenci> getOgrenciler()
    {
        return ogrenciler;
    }

    public void setOgrenciler( List<Ogrenci> ogrenciler )
    {
        this.ogrenciler = ogrenciler;
    }


    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(value = FetchMode.SUBSELECT)
    @JoinTable(name = "sinav_soru",
        joinColumns = {
            @JoinColumn(name = "sinavId", nullable = false)
        },
        inverseJoinColumns = {
            @JoinColumn(name = "soruId", nullable = false)
        }
    )
    public List<Soru> getSorular() {
        return sorular;
    }

    public void setSorular(List<Soru> sorular) {
        this.sorular = sorular;
    }


}

Soru.java(问题)

package tr.edu.gsu.yds.shared.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "soru")
public class Soru implements Serializable
{
    private static final long serialVersionUID = 4L;

    private Integer soruId;
    private String soruTip;
    private String soruMetin;
    private String soruYardimci;
    private Integer soruPuan;
    private List<Cevap> cevaplar = new ArrayList<Cevap>();
    private List<Sinav> sinavlar = new ArrayList<Sinav>();

    @Id
    @GeneratedValue( strategy=GenerationType.IDENTITY )
    @Column(name = "soruId")
    public Integer getSoruId() {
        return soruId;
    }

    public void setSoruId(Integer soruId) {
        this.soruId = soruId;
    }

    @Column( name = "soruTip", nullable = false, length=20 )
    public String getSoruTip() {
        return soruTip;
    }

    public void setSoruTip( String soruTip ) {
        this.soruTip = soruTip;
    }

    @Column( name = "soruMetin", nullable = false, length = 65535, columnDefinition="Text" )
    public String getSoruMetin() {
        return soruMetin;
    }

    public void setSoruMetin( String soruMetin ) {
        this.soruMetin = soruMetin;
    }

    @Column( name = "soruYardimci", nullable = false, length=45 )
    public String getSoruYardimci() {
        return soruYardimci;
    }

    public void setSoruYardimci( String soruYardimci ) {
        this.soruYardimci = soruYardimci;
    }

    @Column( name = "soruPuan", nullable = false, length=3 )
    public Integer getSoruPuan() {
        return soruPuan;
    }

    public void setSoruPuan( Integer soruPuan ) {
        this.soruPuan = soruPuan;
    }

    @OneToMany( mappedBy = "soru", fetch = FetchType.EAGER, cascade=CascadeType.ALL )
    public List<Cevap> getCevaplar() {
        return cevaplar;
    }

    public void setCevaplar( List<Cevap> cevaplar ) {
        this.cevaplar = cevaplar;
    }

    @ManyToMany( mappedBy = "sorular", fetch = FetchType.LAZY )
    public List<Sinav> getSinavlar() {
        return sinavlar;
    }

    public void setSinavlar(List<Sinav> sinavlar) {
        this.sinavlar = sinavlar;
    }

}

这是我获得考试清单的代码;

package tr.edu.gsu.yds.client.controller.ogrenci;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

import tr.edu.gsu.yds.client.remote.YdsRemoteService;
import tr.edu.gsu.yds.client.remote.YdsRemoteServiceAsync;
import tr.edu.gsu.yds.client.view.ogrenci.sinavislemleri.OgrenciWritingSoruSayfasi;
import tr.edu.gsu.yds.shared.domain.Sinav;
import tr.edu.gsu.yds.shared.domain.SinavTakvim;
import tr.edu.gsu.yds.shared.domain.Soru;

public class OgrenciWritingSoruSayfasiController
{

    private YdsRemoteServiceAsync   ydsRemoteServiceAsync   = GWT.create( YdsRemoteService.class );
    private OgrenciWritingSoruSayfasi ogrenciWritingSoruSayfasi;

    public OgrenciWritingSoruSayfasiController( OgrenciWritingSoruSayfasi ogrenciWritingSoruSayfasi )
    {
        this.ogrenciWritingSoruSayfasi = ogrenciWritingSoruSayfasi;

    }

    public void send(){

        ydsRemoteServiceAsync.getSinavList( new AsyncCallback<List<Sinav>>()
        {

            @Override
            public void onSuccess( List<Sinav> result )
            {
                for ( Sinav sinav : result )
                {
                    //Just to see , returning results.
                    Window.alert( "sinav " + sinav.getSinavId() );

                }               
            }

            @Override
            public void onFailure( Throwable caught )
            {
                Window.alert( "Failure" );

            }
        } );
        ogrenciWritingSoruSayfasi.getOgrenciWritingWidget().getOkayButton().addClickHandler( new ClickHandler()
        {

            @Override
            public void onClick( ClickEvent event )
            {
                ogrenciWritingSoruSayfasi.getOgrenciWritingWidget().getSoruMetniLabel().setText( "Basıldı" );

            }
        } );


    }

}
4

3 回答 3

0

我不确定,但根据我从其他问题的答案中读到的,您忘记添加默认(零)参数构造函数。添加后可以再试一次吗?

于 2012-04-08T19:44:09.787 回答
0

省略这些变量及其各自的方法将不适用于 GWT。

private List<Ogrenci> ogrenciler = new ArrayList<Ogrenci>();
private List<Soru> sorular = new ArrayList<Soru>();

两者都不

private Set<Ogrenci> ogrenciler = new HashSet<Ogrenci>();
private Set<Soru> sorular = new HashSet<Soru>();

有不同的解决方案可用,例如推土机、吉利德等。您也可以使用 getbyids 方法来获得这些结果以进行简化。

于 2012-04-08T20:15:24.317 回答
0

交换这些:

  private List<Ogrenci> ogrenciler = new ArrayList<Ogrenci>();
private List<Soru> sorular = new ArrayList<Soru>();

和:

  private Set<Ogrenci> ogrenciler = new HashSet<Ogrenci>();
private Set<Soru> sorular = new HashSet<Soru>();

类似地,其他实体类中的列表。

查看此链接:Serializable Hibernate data object for GWT RPC

于 2012-04-08T19:26:21.563 回答