HibernateSystemException:无法反序列化

时间:2015-11-09 07:03:01

标签: java spring hibernate

我查看了几个类似主题的帖子,但这些都没有帮助我。

我正在使用以下技术:     春天3.2.3.RELEASE     Hibernate 3.5.1-最终版     Spring Security 3.2.3.RELEASE

我的初步立场是,我有三个类(用户,锻炼和事件),彼此之间有关系。以下是课程的必要部分:

User.java

@Entity
@Table
@ManagedBean
public class User implements java.io.Serializable
{
  private static final long serialVersionUID = 1L;
  private Integer id;
  private List<Workout> performances = new ArrayList<Workout>();

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Integer getId()
  {
    return id;
  }

  public void setId(Integer id)
  {
    this.id = id;
  }

@OneToMany(mappedBy = "user")
  public List<Workout> getPerformances()
  {
    return performances;
  }

  public void setPerformances(List<Workout> performances)
  {
    this.performances = performances;
  }

Workout.java

@Entity
@Table
public class Workout implements java.io.Serializable
{
  private static final long serialVersionUID = 1L;
  private int id;
  private User user;
  private Event event;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public int getId()
  {
    return id;
  }

  public void setId(int id)
  {
    this.id = id;
  }

  @ManyToOne
  @JoinColumn(name = "user_fk")
  public User getUser()
  {
    return user;
  }

  public void setUser(User user)
  {
    this.user = user;
  }

  @ManyToOne
  @JoinColumn(name = "e_fk")
  public Event getEvent()
  {
    return event;
  }

  public void setEvent(Event event)
  {
    this.event = event;
  }

Event.java

@Entity
@Table
public class Event implements java.io.Serializable
{
  private static final long serialVersionUID = 1L;
  private Integer id;
  private List<Workout> workouts = new ArrayList<Workout>();

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Integer getId()
  {
    return id;
  }

  public void setId(Integer id)
  {
    this.id = id;
  }

  @OneToMany(mappedBy = "event")
  public List<Workout> getWorkouts()
  {
    return workouts;
  }

  public void setWorkouts(List<Workout> workouts)
  {
    this.workouts = workouts;
  }

这里是 WorkoutDaoImpl 中的方法,它使用一个事件进行所有训练(这个在我的xhtml网站上调用):

 public int getWorkoutsByUserId(String id)
  {    
     return
     (List<Workout>)getHibernateTemplate().find("from Workout where user_fk       like '" + id + "' and e_fk IS NOT null");
  }

所以在这里 Stacktrace

javax.el.ELException: /workout.xhtml @19,101 value="#{workoutDao.getWorkoutsByUserId(user.id)}": org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) at javax.faces.component.UIData.getValue(UIData.java:732) at org.primefaces.component.api.UIData.getDataModel(UIData.java:758) at javax.faces.component.UIData.getRowCount(UIData.java:356) at org.primefaces.component.api.UIData.calculateFirst(UIData.java:209) at org.primefaces.component.datatable.DataTableRenderer.preRender(DataTableRenderer.java:115) at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:83) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903) at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:451) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.java:163) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.myApp.helpers.CharsetFilter.doFilter(CharsetFilter.java:38) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: javax.el.ELException: org.springframework.orm.hibernate3.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize at javax.el.BeanELResolver.invoke(BeanELResolver.java:489) at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161) at org.apache.el.parser.AstValue.getValue(AstValue.java:173) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)

我的个人意见是,我可能有一个hibernate映射问题(导致序列化问题)。我的hibernate查询有时会工作,当我搜索e_fk为NULL时,这非常有趣。在堆栈跟踪的末尾还有一些java.io.StreamCorruptedException:无效的流标头:7777772E异常,也许这会有所帮助。

如果您有任何想法,我已搜索过所有帖子,会很棒。如果您需要更多文件,请索取。 applicationContext和hibernateProperties应该是正确的。

谢谢。

1 个答案:

答案 0 :(得分:2)

所以,问题非常烦人。我有一个URL类型的字段,无法序列化。所以每个人都有这个例外。检查所有字段中的特殊数据类型,并为它们提供正确的注释。

并且也不要忘记做正确的映射(mappedBy),这应该可以解决你的问题。您不需要实现Serializable或@Transient。