在尝试构建会话工厂时,我得到了这个。很少出现在互联网搜索中。但这几天让我死在水里。谢谢。
java.lang.NoSuchMethodError: org.hibernate.cfg.Environment.verifyProperties(Ljava/util/Map;)V
at org.hibernate.service.ServiceRegistryBuilder.buildServiceRegistry(ServiceRegistryBuilder.java:244)
使用休眠版本:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.1.1.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.1.Final</version>
</dependency>
public class HibernateUtils {
private static final String DATABASE_HOST = "host_to_db";
private static SessionFactory factory;
private static ServiceRegistry serviceRegistry;
public static void init() {
Configuration config = getConfiguration();
config.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(
config.getProperties()).buildServiceRegistry();
config.setSessionFactoryObserver(new SessionFactoryObserver() {
@Override
public void sessionFactoryCreated(SessionFactory factory) { }
@Override
public void sessionFactoryClosed(SessionFactory factory) {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
});
factory = config.buildSessionFactory(serviceRegistry);
}