Final Initialized 问题
The blank final field sessionFactory may not have been initialized
这个错,很操蛋,刚开始上网找,找了很久,所以留下作为笔记使用。
throw new HibernateException(e.getMessage());
eclipse编译private static final SessionFactory sessionFactory;这行就会报错,报错如下:
Multiple markers at this line
- The value of the field TestHibernate.sessionFactory is
not used
- The blank final field sessionFactory may not have been
initialized
解决方法一:
private static final SessionFactory sessionFactory;
static{
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new HibernateException(e.getMessage());
}
}
}
解决方法2:
static{try {sessionFactory = new Configuration().configure().buildSessionFactory();} catch (HibernateException e) {// TODO Auto-generated catch block//e.printStackTrace();//throw new HibernateException(e.getMessage());sessionFactory = null; //这里初始化一下}

浙公网安备 33010602011771号