【发布时间】:2017-03-24 00:24:34
【问题描述】:
我正在使用 JavaFX+Hibernate 创建桌面应用程序,但是在用户使用他/她的 用户名 登录后,我希望将用户名分配给类似于 PHP @ 的全局变量987654321@ 可以从任何地方访问的变量。
这是我的 HibernateUtil.java 类的代码
package models;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
public static SessionFactory buildSessionFactory(){
try{
// Create the SessionFactory from hibernate.cfg.xml
System.out.println("creating SessionFactory using HibernateUtil.java");
SessionFactory f = new Configuration().configure().buildSessionFactory();
System.out.println("session created successfully");
return f;
} catch (Throwable ex){
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
【问题讨论】:
标签: java hibernate session javafx hql