gpt4 book ai didi

java - hibernate 4 : ViolatedConstraintNameExtracter exception

转载 作者:行者123 更新时间:2023-11-29 05:29:47 24 4
gpt4 key购买 nike

我正在尝试在 Maven 项目中设置 Hibernate 4。它不起作用,这让我发疯。

我得到这个异常:

java.lang.NoClassDefFoundError: org/hibernate/exception/ViolatedConstraintNameExtracter

这些是在 pom.xml 文件中声明的依赖项:

 <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.dialect</groupId>
<artifactId>sqlite-dialect</artifactId>
<version>0.1.0</version>
<scope>provided</scope>
</dependency>

这是我的 Hibernate 配置文件:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.sqlite.JDBC</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:sqlite:test.db</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLiteDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>

这是“崩溃”的代码:

Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);

我只有一个名为“User”的测试模型,并用 Hibernate 注释装饰。

你能帮我解决这个问题吗?干杯。

更新:堆栈跟踪

Initial SessionFactory creation failedjava.lang.NoClassDefFoundError:    org/hibernate/exception/ViolatedConstraintNameExtracter
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.matteopacini.RestaurantManager.HibernateUtil.<clinit>(HibernateUtil.java:27)
at com.matteopacini.RestaurantManager.App.main(App.java:14)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/exception/ViolatedConstraintNameExtracter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:242)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor (StrategySelectorImpl.java:125)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:155)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:136)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:78)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:68)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:165)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at com.matteopacini.RestaurantManager.HibernateUtil.<clinit>(HibernateUtil.java:21)
... 1 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.exception.ViolatedConstraintNameExtracter
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more

最佳答案

您使用的方言与 Hibernate 4 不兼容。参见 https://github.com/gwenn/sqlite-dialect/blob/master/src/main/java/org/hibernate/dialect/SQLiteDialect.java : 它使用 org.hibernate.exception.ViolatedConstraintNameExtracter,在 Hibernate 4 中已移至 org.hibernate.exception.spi.ViolatedConstraintNameExtracter

关于java - hibernate 4 : ViolatedConstraintNameExtracter exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21514980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com