2011-04-22 113 views
0

嘿大家好!我正在開發一個GWT + Spring + Hibernate的應用程序,但是當我運行它,我得到這個錯誤:GWT休眠彈簧序列化問題

[WARN] Exception while dispatching incoming RPC call 
com.google.gwt.user.client.rpc.SerializationException: Type 'org.springframework.orm.jpa.JpaSystemException' 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.orm.jpa.JpaSystemException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.karq.saatekava.shared.dto.TelekanalDTO; nested exception is javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.karq.saatekava.shared.dto.TelekanalDTO 
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:614) 
    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:152) 
    at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534) 
    at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616) 
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:390) 
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588) 
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:551) 
    at org.spring4gwt.server.SpringGwtRemoteServiceServlet.processCall(SpringGwtRemoteServiceServlet.java:37) 
    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) 
[ERROR] 500 - POST /saatekava/springGwtService/telekanalService (127.0.0.1) 57 bytes 

回答

0

你有2個問題:

  1. 您正在嘗試堅持分離對象。你應該合併它。
  2. 1)引起的異常不可序列化,因爲GWT沒有注意到它在您的rpc服務簽名中。簡單的解決方案 - 在RPC服務方法中捕獲異常並拋出自定義異常。

退房Gilead,它可能幫助。

public void someRpcMethod() throws MyException{ 
    try{ 
    dosomething(); 
    }catch(RuntimeException e){ 
    throw new MyException("something failed", e); 
    } 
} 

Tt可能是個好主意,不要將所有異常傳遞給客戶端,並以不同方式處理它們。在這裏您可以獲得更多信息:http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html#exceptions