tomcat restart =>找不到SessionFactory [uuid = ...,name = null] [英] tomcat restart => Could not find a SessionFactory [uuid=...,name=null]
问题描述
继续解决这种情况,我已更新 hibernate
ond sqljdbc4
jars
现在异常已被修改(请看一看
使用
- Hibernate v4.1.4 FINAL
- JSF 2.1(mojarra)
- 所有我的
@ManagedBeans
执行可串行化
它与 @ViewScoped
,因为 @SessionScoped
bean都可以使用
我尝试过:
-
启用
< Manager pathname =/>在context.xml
中,是的,异常消失了,但我真的失去了永久会话,所以我必须在tomcat服务器重新启动后重新登录。 -
在hiberanate.cfg.xml文件中进行更改(例如将
name =java:hibernate / SessionFactory
添加到< session-
-
使用
SESSIONS.ser
文件,它是在 STOP tomcat服务器之后创建的。
- 当我打开 ser文件时,我可以找到如下所示的内容:.... <$ c $如果我再次START tomcat服务器,则可以使用
-
- 它报告
找不到SessionFactory [uuid = 8906373-f31b-4990-833c-c7680b2a77ce,name = null]
- WHY ??? session似乎存在于SESSION.ser
文件中...... - 当我打开 ser文件时,我可以找到如下所示的内容:.... <$ c $如果我再次START tomcat服务器,则可以使用
我的会话管理器:
@SessionScoped
@ManagedBean(name =userManager)
public class UserManager实现Serializable {
private static final long serialVersionUID = 1L;
私有瞬态HttpSession会话;
私人字符串用户名;
私人字符串密码;
私人用户用户;
$ b $ public String login(){
//这里是为数据库中的用户进行分页(基于用户名和密码)
if(user!= null){
FacesContext context = FacesContext.getCurrentInstance();
session =(HttpSession)context.getExternalContext()。getSession(true);
session.setAttribute(id,user.getId());
session.setAttribute(username,user.getName());
...
返回成功;
public String logout(){
user = null;
FacesContext context = FacesContext.getCurrentInstance();
session =(HttpSession)context.getExternalContext()。getSession(true);
...
session.invalidate();
返回成功;
}
// getters and setters ------------------------------------ ----------------
}
我的 hibernate.cfg.xml
:
<?xml version = 1.0encoding =UTF-8?>
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置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>密码< / 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>线程< / property>
< property name =hibernate.show_sql> true< / property>
< property name =hibernate.hbm2ddl.auto>更新< / 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:java.io.InvalidObjectException:找不到SessionFactory [uuid = f9c33312-cf7f-4f65-ae5f -44261705c18e,name = null]
java.io.InvalidObjectException:无法在org.hibernate.internal中找到SessionFactory [uuid = f9c33312-cf7f-4f65-ae5f-44261705c18e,name = null]
。 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:从持久存储装载会话的异常
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)
....
您是否遇到过这个错误报告?
您不希望 Session , SessionFactor y 或 DaoSF 进行序列化。它们是暂时的,不能从文件中恢复。你最好弄清楚它们在哪里以及为什么序列化到文件中。这就是您需要修复的地方。
Continue solving this situation, I've updated hibernate
ond sqljdbc4
jars
and the exception is changed now (please take a look bellow).
I'm using
- Hibernate v4.1.4 FINAL
- JSF 2.1 (mojarra)
- all my
@ManagedBeans
implements Serializable
It has some relation to @ViewScoped
, because @SessionScoped
beans are OK
What I've tried:
enable
<Manager pathname=""/> in context.xml
, and yes, the exception disappears, but I really lose persistent sessions, so I have to login again after tomcat server restart.make changes in hiberanate.cfg.xml file (e.g. add
name="java:hibernate/SessionFactory"
to<session-factory>
tag), but without successplay with
SESSIONS.ser
file, which is created after STOP the tomcat server.- When I open ser file, I can find there something like: ....
uuidq ~ xppt $e8906373-f31b-4990-833c-c7680b2a77ce
... - if i START tomcat server again, it reports
Could not find a SessionFactory [uuid=8906373-f31b-4990-833c-c7680b2a77ce,name=null]
- WHY??? The session seems to be present inSESSION.ser
file...
- When I open ser file, I can find there something like: ....
My session manager:
@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 ----------------------------------------------------
}
my 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>
and my session factory:
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) {
...
}
}
}
exception:
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)
....
I've tried to edit my hibernate.cfg.xml
file this way:
<session-factory name="java:hibernate/SessionFactory">
And the error reportd has been changed to:
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)
....
Don't you ever met with this error reports?
You don't want instances of Session, SessionFactory or DaoSF to be serialized. They are transient and cannot be restored from a file. You better figure out where and why they are serialized to a file in the first place. That's where you need to make a fix.
这篇关于tomcat restart =>找不到SessionFactory [uuid = ...,name = null]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!