继续解决这种情况,我已经更新了hibernate
ond sqljdbc4
jars
,现在异常已更改(请看下面)。
我正在使用
- 休眠 v4.1.4 最终版
- JSF 2.1 (莫哈拉)
- 我所有的
@ManagedBeans
implements Serializable
它与 有一些关系@ViewScoped
,因为@SessionScoped
bean 还可以
我试过的:
enable
<Manager pathname=""/> in context.xml
,是的,异常消失了,但我真的失去了持久会话,所以我必须在 tomcat 服务器重启后再次登录。在 hibernate.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
文件中......
- 当我打开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)
....
你没有遇到过这个错误报告吗?