#################一个关于静态属性的问题
在Hibernate的帮助文档里面的Quickstart with Tomcat一章看到这段代码
public class HibernateUtil {
private static Log log = LogFactory.getLog(HibernateUtil.class); private static final SessionFactory sessionFactory; static { try { // Create the SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed log.error( "Initial SessionFactory creation failed. ", ex); throw new
ExceptionInInitializerError(ex); } } public static final ThreadLocal session = new ThreadLocal();
------解决方案--------------------这部分相当于类的初始化,因为static是在类的概念上说的,没有构造函数一说,要把初始化的东西都放在static{}里面,相当于instance调用构造函数类似的
------解决方案--------------------执行一次,因为它是static的。