【问题标题】:Eclipse: Cannot use Hibernate tool plugin to generate cfg xmlEclipse:无法使用 Hibernate 工具插件生成 cfg xml
【发布时间】:2014-01-12 08:09:59
【问题描述】:

我按照 spring 教程构建了一个安静的可执行 jar。 http://spring.io/guides/gs/rest-service/

我正在使用 Eclipse,并且是第一次配置 Hibernate。我知道 hibernate cfg xml 文件可以由 eclipse hibernate 配置插件生成(根据http://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/)。我已经安装了它,并配置了与我的数据库的连接。

当我尝试刷新数据库视图以查看子对象时,出现错误:

An internal error occurred during: "Fetching children of Database".
org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V

我的 POM 非常简单。

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

    <groupId>com.mydomain</groupId>
    <artifactId>myapp</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>0.5.0.M6</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>         
        </dependency>
    </dependencies>

    <properties>
        <start-class>com.mydomain.myapp.Application</start-class>
    </properties>

    <build>
        <plugins>
            <plugin> 
                <artifactId>maven-compiler-plugin</artifactId> 
                <!-- <version>2.3.2</version> --> 
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>          
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/libs-snapshot</url>
            <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

我了解此问题可能是由于在运行以获取 db 子项时与 Hibernate 冲突的依赖项加载 LocationAwareLogger 引起的。

我已经将父 pom 追溯到 spring-boot-dependencies https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependencies/pom.xml 我发现 slf4j 加载的地方。我想这就是问题所在。

我在这里超出了我的深度。如何实现配置 Hibernate eclipse 插件以生成我的 cfg.xml 文件的目标?有没有办法排除在祖父母 pom 中加载的 slf4j?

谢谢

【问题讨论】:

  • 可能你需要通过mvn depenenty:tree显示所有的依赖继承,然后添加maven依赖排除排除其他依赖中的冲突依赖,只使用hibernate的。
  • 在eclipse中,我可以看到依赖层次结构。 slf4j 是从 spring-boot-starter-logging 加载的,由 spring-boot-starter 调用,由 spring-boot-starter-web 调用。但是那些在我的父 pom 中,或者我的父 pom 的父级中......我怎样才能排除那些?

标签: eclipse spring hibernate maven slf4j


【解决方案1】:

@Leo Huang 向我指出该文件时是对的。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-logging</artifactId>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
        </exclusion>
    </exclusions> 
</dependency>

【讨论】:

    【解决方案2】:

    删除eclipse的artifacts.xml上的所有slf4j配置。然后重启eclipse,重做hibernate工具进程。

    【讨论】:

      【解决方案3】:

      避免修改项目行为的解决方案,因此只修改 Hibernare Tools 插件,是在项目中编辑 hibernate 的配置:

      1. 转到类路径面板
      2. 删除项目条目类路径
      3. 在文件夹中添加hibernate工具插件的External JARs库:eclipse\plugins\org.hibernate.eclipse.libs_3.7.1.Final-v20140303-0022-B124\lib\hibernate
      4. 在 pom.xml 中临时注释掉记录 SLF4J 的库块。
      5. 重启 Eclipse

      使用工具后,恢复pom.xml。

      【讨论】:

        【解决方案4】:

        我也碰巧遇到了同样的问题,如上所述,我不得不从 POM 中排除所有 sl4j jar。 重要的是在那之后重新启动 Eclipse。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-01-04
          • 1970-01-01
          • 2016-04-03
          • 1970-01-01
          • 2015-06-20
          • 2012-02-17
          • 2010-12-02
          • 1970-01-01
          相关资源
          最近更新 更多