【问题标题】:Import hibernate into a project in Eclipse将hibernate导入Eclipse中的项目
【发布时间】:2015-10-19 12:14:42
【问题描述】:

我正在从事一个已经由其他人开发的项目,我实际上正在尝试运行它。该项目正在使用 Hibernate,但所有导入都在 Eclipse 中创建错误。我发现该项目需要一个配置休眠的 .xml 文件,但我不知道是否是问题所在。

这是项目中的导入:

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.CriteriaSpecification;

这是 .xml 文件:

<?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="connection.driver_class">com.mysql.jdbc.Driver</property>

    <property name="connection.datasource">java:persystDs</property>        
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>  
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.cache.use_second_level_cache">false</property>
    <property name="hibernate.cache.use_query_cache">false</property>
    <property name="show_sql">false</property>  
    <property name="hbm2ddl.auto">update</property>

    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>


    <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

</session-factory>

请帮忙!

编辑:

这是休眠的部分:

<exclusion>
                <groupId>eu.akka.jbossas</groupId>
                <artifactId>hibernate-commons-annotations</artifactId>
            </exclusion>
            <exclusion>
                <groupId>eu.akka.jbossas</groupId>
                <artifactId>hibernate-core</artifactId>
            </exclusion>
<exclusion>
                <groupId>eu.akka.jbossas</groupId>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>eu.akka.jbossas</groupId>
                <artifactId>hibernate-validator</artifactId>
            </exclusion>



<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
        <exclusions>
            <exclusion>
                <artifactId>javassist</artifactId>
                <groupId>javassist</groupId>
            </exclusion>
        </exclusions>
    </dependency>



<dependency>
        <groupId>fr.inra.grignon</groupId>
        <artifactId>persyst-common</artifactId>
        <version>1.0-SNAPSHOT</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

【问题讨论】:

  • 你使用 Maven 还是 ANT 来构建你的项目?
  • 阅读错误信息可能很有用,你不觉得吗?你为什么使用 JBoss 和 Tomcat。它们是多余的。
  • @Erlaunis 你真的需要退后一步,首先学习 Maven 的基础知识。
  • @GillesBodart 我编辑了
  • 好像?他们显然没有,否则eclipse会找到罐子,你不会看到像“导入无法解决”这样的错误

标签: java eclipse hibernate


【解决方案1】:

您的项目似乎没有很好地导入,

你能再导入一次吗?

选择后

然后你选择你的项目

如果你不能添加你的项目,也许用这个改变所有的 pom.xml

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.inra.grignon</groupId>
<artifactId>fr.inra.grignon.hibernate</artifactId>

<dependencies>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
        <exclusions>
            <exclusion>
                <artifactId>javassist</artifactId>
                <groupId>javassist</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>fr.inra.grignon</groupId>
        <artifactId>persyst-common</artifactId>
        <version>1.0-SNAPSHOT</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies> 
</project>

【讨论】:

  • alt+F5 后,可用的 Maven 代码库列表中什么都没有
  • @Erlaunis 它应该:) 右键单击​​ pom.xml,你有 Maven 子菜单吗?
  • Yes : "添加依赖,添加插件,新建maven项目模块并选择maven配置文件"
  • 我正在尝试,但它在没有所有包的情况下导入
  • 是因为你的pom.xml不好,你是把所有的pom都放了还是只放了一小部分?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 2013-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-04
  • 2012-02-18
相关资源
最近更新 更多