gpt4 book ai didi

java.lang.NoClassDefFoundError : org/hibernate/criterion/Criterion 错误

转载 作者:行者123 更新时间:2023-11-28 23:45:16 25 4
gpt4 key购买 nike

我在 eclipse Juno、Spring 3.1.1、hibernate 4.1、tomcat 7 和 mySQL 中使用 STS。

我创建了一个简单的 MVC 模板项目。我的目的是用户将一些数据输入到表单中,并且该数据将保存在数据库中。

我创建了:

网络层:

  1. 简单的形式。
  2. 从表单接收数据并将其传递给服务层的 Controller 。

服务层:

一个服务类,它包含一个 DAO 字段并运行一个 dao 方法。

数据访问层:

  1. 不与数据库通信的模拟 DAO 实现。
  2. 不与数据库通信的 Real DAO 实现。

当我使用模拟 DAO 实现检查系统时,一切正常 - 从 Web 层到模拟 DAO。

但是当注入(inject)真正的 DAO 时,我只是得到一个 404 错误,而数据库中没有发生任何事情。

我将只展示 DAO 实现和 root-context.xml,因为这是我认为的问题所在。

我的 DAO 实现:

@Repository
public class Presentation_page_dao_hibernate_Impl implements Presentation_page_dao {

private SessionFactory sessionFactory;

@Autowired
public Presentation_page_dao_hibernate_Impl(SessionFactory sessionFactory) {
this.sessionFactory=sessionFactory;
System.out.println("Hi! i'm in ActionDao_HibernateImpl constructor");
}

private Session currentSession() {
return sessionFactory.getCurrentSession();
}


public void create(Presentation_page pp) {
currentSession().beginTransaction();
currentSession().save(pp);
currentSession().getTransaction().commit();
currentSession().close();
}


public Presentation_page read(int pageid) throws PresentationPageNotFoundException {


currentSession().beginTransaction();

Criteria criteria=currentSession().createCriteria(Presentation_page.class);

criteria.add(Restrictions.eq("page_id", pageid));
List<Presentation_page> list_of_pages=criteria.list();

currentSession().getTransaction().commit();
currentSession().close();

for(Presentation_page pp:list_of_pages) {
if (pp.getPage_id()==pageid){
return pp;
}
}
return null;
}

public void update(Presentation_page pp) throws PresentationPageNotFoundException {

currentSession().beginTransaction();
currentSession().update(pp);
currentSession().getTransaction().commit();
currentSession().close();

}

@Override
public void delete(Presentation_page pp) throws PresentationPageNotFoundException {

currentSession().beginTransaction();
currentSession().delete(pp);
currentSession().getTransaction().commit();
currentSession().close();
}

}

这是我的 root-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- Root Context: defines shared resources visible to all other web components -->


<!-- For annotations -->
<context:component-scan
base-package="my.topLevel.pack">
</context:component-scan>

<import resource="hibernate2.xml"/>


</beans>

这是我的 hibernate.xml:

<!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>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/spring_presentation</property>
<property name="connection.username">rotemya</property>
<property name="connection.password">*******</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>


<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<!-- Names the annotated entity class -->
<mapping class="my.topLevel.pack.Domain"/>

</session-factory>
</hibernate-configuration>

我对 pom.xml 有以下依赖关系:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.topLevel</groupId>
<artifactId>pack</artifactId>
<name>SpringSTS_Sample_Project</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.13</version>
</dependency>
</dependencies>

</project>

这是我的 hibernate jar 文件:

enter image description here

我收到以下错误:

java.lang.NoClassDefFoundError: org/hibernate/criterion/Criterion

有什么想法吗?

最佳答案

好的-问题解决了!

我从 hibernate 库文件(我创建的)中删除了所有 jar,并通过 Maven(pom.xml 文件)添加它们。错误消失了..

关于java.lang.NoClassDefFoundError : org/hibernate/criterion/Criterion 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15078614/

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