继续解决this situation,我已更新hibernate
ond sqljdbc4
jars
,现在更改了例外情况(请查看下面的内容)。
我正在使用
@ManagedBeans
implements Serializable
它与@ViewScoped
有一定的关系,因为@SessionScoped
bean没问题
我尝试了什么:
启用<Manager pathname=""/> in context.xml
,是的,异常消失,但我确实失去了持久会话,所以我必须在tomcat服务器重启后再次登录。
在hiberanate.cfg.xml文件中进行更改(例如将name="java:hibernate/SessionFactory"
添加到<session-factory>
代码),但没有成功
使用SESSIONS.ser
文件,该文件是在停止 tomcat服务器之后创建的。
uuidq ~ xppt $e8906373-f31b-4990-833c-c7680b2a77ce
... 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)
....
你有没有遇到过这个错误报告?
答案 0 :(得分:2)
您不希望序列化 Session , SessionFactory 或 DaoSF 的实例。它们是瞬态的,无法从文件中恢复。您最好先找出它们序列化到文件的位置和原因。这就是你需要修复的地方。
答案 1 :(得分:2)
另一个功能是更新tomcat / conf /下的context.xml,详细信息如下:
<Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="false" maxActiveSessions="-1" minIdleSwap="-1" maxIdleSwap="-1" maxIdleBackup="-1">
<Store className="org.apache.catalina.session.FileStore"/>
</Manager>