以下是我的java课程。我正在使用Hibernate 5.2.11和jdk1.8。即使我尝试过其他5.2.x版本,但我的程序仍然只是从第一行代码中退出(在课堂上提到)。
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
public class HibernateCfg {
// private static final Logger logger =
// LogManager.getLogger(HibernateCfg.class.getName());
private static HibernateCfg hc = null;
private static final Object object = new Object();
private SessionFactory sessionFactory;
private StandardServiceRegistry registry;
private Session session;
private HibernateCfg() {
sessionFactory = getSessionFactory();
// Create registry
}
private SessionFactory getSessionFactory() {
try {
//code stops here at below line
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
.configure("/hibernate.cfg.xml").build();
Metadata metadata = new MetadataSources(standardRegistry).getMetadataBuilder().build();
sessionFactory = metadata.getSessionFactoryBuilder().build();
return sessionFactory;
} catch (Exception e) {
}
return null;
}
public static HibernateCfg getObject() {
if (hc == null) {
synchronized (object) {
if (hc == null) {
hc = new HibernateCfg();
}
}
}
return hc;
}
什么似乎是问题?