java.lang.NoSuchMethodError:org.hibernate.cfg.Environment.verifyProperties

时间:2012-07-19 02:43:05

标签: hibernate

在尝试构建会话工厂时我得到了这个。在互联网搜索中很少出现。但它现在已经让我死了几天了。感谢。

java.lang.NoSuchMethodError: org.hibernate.cfg.Environment.verifyProperties(Ljava/util/Map;)V
at   org.hibernate.service.ServiceRegistryBuilder.buildServiceRegistry(ServiceRegistryBuilder.java:244)

使用hibernate版本:

<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);
}

1 个答案:

答案 0 :(得分:6)

您与hibernate-core.jar版本存在冲突,Map版本仅在更高版本中添加(可能在4.2.X左右?),请检查您的Eclipse / Maven“依赖层次结构”选项卡以分析版本冲突。

public static void verifyProperties(Map<?,?> configurationValues)

只有当我删除了我的本地Hibernate Maven仓库并再次运行安装时,我的问题才得以解决。