我的同学说用注解的话AnnotationConfiguration().buildSessionFactory()就可以,而不需要AnnotationConfiguration()
.configure().buildSessionFactory()但是我的一个测试小项目用前者报错,用后者就OK。而且我查了文档确实注解用的是前者。什么原因呢?求高手帮忙啊。
.configure().buildSessionFactory()但是我的一个测试小项目用前者报错,用后者就OK。而且我查了文档确实注解用的是前者。什么原因呢?求高手帮忙啊。
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static AnnotationConfiguration configuration = new AnnotationConfiguration(); private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION; static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
这是你反编译的结果吧,你再编译hibernate-jpa-2.0这个包看下,我估计它没有前面那一句(我没用过SDK反编译,你试试吧,顺便告诉我下~~谢谢)