小编典典

tomcat restart =>找不到SessionFactory [uuid =…,名称= null]

tomcat

继续解决这种情况,我已经更新了hibernateond sqljdbc4
jars,现在更改了异常(请看下面)。

我在用着

  • Hibernate v4.1.4最终版
  • JSF 2.1(mojarra)
  • 我所有的 @ManagedBeans implements Serializable

它与有关@ViewScoped,因为@SessionScopedbean可以

我尝试过的

  • enable <Manager pathname=""/> in context.xml,是的,该异常消失了,但是我真的失去了持久会话,因此必须在tomcat服务器重启后再次登录。

  • 在hiberanate.cfg.xml文件中进行更改(例如,添加name="java:hibernate/SessionFactory"<session-factory>标签),但是没有成功

  • 播放SESSIONS.ser文件,该文件是在Tomcat服务器 停止 后创建的。

    • 当我 打开 SER文件,我可以发现有这样的:… uuidq ~ xppt $e8906373-f31b-4990-833c-c7680b2a77ce
    • 如果我再次 启动 tomcat服务器,它会报告Could not find a SessionFactory [uuid=8906373-f31b-4990-833c-c7680b2a77ce,name=null]- 为什么? 该会话似乎存在于SESSION.ser文件中…

我的 会话管理器:

@SessionScoped
@ManagedBean(name="userManager")
public class UserManager implements Serializable {
  private static final long serialVersionUID = 1L;
  private transient HttpSession session;
  private String username;
  private String password;
  private User user;

  public String login() {
    // here is seraching for user in database (based on username and password)

    if (user != null) {
      FacesContext context = FacesContext.getCurrentInstance();
      session = (HttpSession) context.getExternalContext().getSession(true);
      session.setAttribute("id", user.getId());
      session.setAttribute("username", user.getName());
      ...
      return "success";
    } 
  }

  public String logout() {
    user = null;
    FacesContext context = FacesContext.getCurrentInstance();
    session = (HttpSession) context.getExternalContext().getSession(true);
    ...     
    session.invalidate();
    return "success";
  }
  // getters and setters ----------------------------------------------------
}

我的hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC 
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
 <session-factory>
  <property name="connection.url">jdbc:sqlserver://localhost;databaseName=RXP</property>
  <property name="connection.username">user</property>
  <property name="connection.password">password</property>
  <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
  <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
  <property name="current_session_context_class">thread</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.hbm2ddl.auto">update</property>

  <mapping class="tables.User"/>

 </session-factory>
</hibernate-configuration>

和我的 会话工厂

public final class DaoSF implements Serializable {
  private static final long serialVersionUID = 1L;

  private static SessionFactory sessionFactory;
  private static ServiceRegistry serviceRegistry;

  public static SessionFactory getSessionFactory() {
    try {
      Configuration configuration = new Configuration();
      configuration.configure("hibernate.cfg.xml");
      serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
      sessionFactory = configuration.buildSessionFactory(serviceRegistry);
      return sessionFactory;
    }
    catch (HibernateException he) { 
      ...
    }
  }
}

例外情况

30.6.2012 13:29:07 org.apache.catalina.session.StandardManager doLoad
SEVERE: IOException while loading persisted sessions: java.io.InvalidObjectException: Could not find a SessionFactory [uuid=f9c33312-cf7f-4f65-ae5f-44261705c18e,name=null]
java.io.InvalidObjectException: Could not find a SessionFactory [uuid=f9c33312-cf7f-4f65-ae5f-44261705c18e,name=null]
    at org.hibernate.internal.SessionFactoryImpl.locateSessionFactoryOnDeserialization(SessionFactoryImpl.java:2007)
    at org.hibernate.internal.SessionFactoryImpl.deserialize(SessionFactoryImpl.java:2037)
....

我试图用hibernate.cfg.xml这种方式编辑文件:

<session-factory name="java:hibernate/SessionFactory">

并且报告的错误已更改为:

30.6.2012 13:38:23 org.apache.catalina.session.StandardManager startInternal
SEVERE: Exception loading sessions from persistent storage
java.lang.NullPointerException
    at java.util.concurrent.ConcurrentHashMap.get(Unknown Source)
    at org.hibernate.internal.SessionFactoryRegistry.getSessionFactory(SessionFactoryRegistry.java:140)
    at org.hibernate.internal.SessionFactoryRegistry.getNamedSessionFactory(SessionFactoryRegistry.java:135)
    at org.hibernate.internal.SessionFactoryImpl.locateSessionFactoryOnDeserialization(SessionFactoryImpl.java:2000)
    at org.hibernate.internal.SessionFactoryImpl.deserialize(SessionFactoryImpl.java:2037)
....

您从未遇到此错误报告吗?


阅读 410

收藏
2020-06-16

共1个答案

小编典典

您不希望将 SessionSessionFactoryDaoSF的
实例序列化。它们是暂时的,无法从文件中还原。您最好首先弄清楚它们在何处以及为什么被序列化到文件中。那是您需要进行修复的地方。

2020-06-16