gaf*_*fcz 4 eclipse jsf tomcat hibernate
我InvalidObjectException: Could not find a SessionFactory named: null
重新启动tomcat服务器后得到了.
我找到了一些可能的解决方案:
如果您尝试序列化已断开连接的Hibernate会话并在其他VM中反序列化,或者,如果类加载器已重新启动(例如,在应用程序服务器或Web容器中的热重新部署期间),则会发生此异常.这在Tomcat中尤为明显.在应用程序服务器中,总是使用JNDI来存储SessionFactory,如文档所述.在Tomcat或其他Web容器中, 在上下文重新加载期间禁用HttpSession序列化.这有副作用,在Web容器的文档中有解释.
我该怎么做?在上下文重新加载期间禁用HttpSession序列化?
注意:我在Eclipse中使用Tomcat7.
更新:
我已尝试在context.xml
以下位置启用此标记:
<Manager pathname="" />
是的,异常消失,但我失去了持久性会话,所以我必须在tomcat服务器重启后再次登录.
我是否理解会话持久性,如果我相信,在例如JSF应用程序中重启tomcat之后应保留该会话(并且我不能通过登录创建新会话)?
UPDATE2(会话管理员):
@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 ----------------------------------------------------
}
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
我的会议工厂:
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) {
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
你应该能够把它变成:
<Manager pathname="" />
Run Code Online (Sandbox Code Playgroud)
在Tomcat配置文件的Context部分中.
请参阅Tomcat文档:
配置参考 > Manager组件 > 禁用会话持久性
归档时间: |
|
查看次数: |
2727 次 |
最近记录: |