gpt4 book ai didi

java - ClassCastException InjectedDataSourceConnectionProvider Spring 3.1.0、Hibernate 4、JPA EntityManagerFactory

转载 作者:搜寻专家 更新时间:2023-11-01 03:56:54 24 4
gpt4 key购买 nike

使用:

  • Spring 3.1.0
  • hibernate 4
  • JPA 2
  • GWT 2.3.0。

[类似于Exception in GWT Dev Mode + Spring 3.1 + Hibernate 4.0.1 ]

当运行一个非常简单的 GWT 应用程序(使用 Greeting Service)并向应用程序添加 spring 配置(通过 web.xml 和相关的 spring 配置文件)时,系统在 gwt dev 模式下启动时发生异常(从 Eclipse 和命令行 (mvn gwt:run))。

异常如下图所示:

[WARN] Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jgkgwtclasscastissueEntityManagerFactory' defined in ServletContext resource [/WEB-INF/classes/spring-main-config.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: jgkgwtclasscastissue-PU] Unable to build EntityManagerFactory: java.lang.ClassCastException: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider

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">

<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.gs</groupId>
<artifactId>jgkgwtclasscastissue</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>GWT Maven Archetype</name>

<properties>
<gwtVersion>2.3.0</gwtVersion>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<webappDirectory>${project.build.directory}/${project.build.finalName} </webappDirectory>
<antlr.version>2.7.6</antlr.version>
<aopalliance.version>1.0</aopalliance.version>
<c3p0.version>0.9.1.2</c3p0.version>
<cglib.version>2.2.2</cglib.version>
<commons-beanutils.version>1.8.3</commons-beanutils.version>
<commons-collections.version>3.1</commons-collections.version>
<commons-logging.version>1.1.1</commons-logging.version>
<ojdbc6.version>11.1.0.7.0</ojdbc6.version>
<commons-dbcp.version>1.4</commons-dbcp.version>
<dom4j.version>1.6.1</dom4j.version>
<ehcache.version>2.4.6</ehcache.version>
<javassist.version>3.9.0.GA</javassist.version>
<javax.inject.version>1.0-PFD-1</javax.inject.version>
<javax.transaction.version>1.1</javax.transaction.version>
<junit.version>4.9</junit.version>
<log4j.version>1.2.16</log4j.version>
<slf4j-api.version>1.6.1</slf4j-api.version>
<slf4j-log4j12.version>1.6.1</slf4j-log4j12.version>

<org.aspectj.version>1.6.10</org.aspectj.version>
<org.hibernate.version>4.0.0.Final</org.hibernate.version>
<org.hibernate-commons-annotations.version>4.0.1.Final</org.hibernate-commons-annotations.version>
<org.hibernate.hibernate-validator.version>4.1.0.Final</org.hibernate.hibernate-validator.version>
<org.hibernate.jpamodelgen.version>1.1.1.Final</org.hibernate.jpamodelgen.version>
<org.springframework.version>3.1.0.RELEASE</org.springframework.version>
<org.springframework.data.version>1.0.1.RELEASE</org.springframework.data.version>
<wagon-ssh.version>1.0-beta-6</wagon-ssh.version>

</properties>

<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
</dependency>

<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>2.3.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>${org.hibernate-commons-annotations.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${org.hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${org.hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>${aopalliance.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${org.aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument-tomcat</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${org.springframework.data.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${commons-beanutils.version}</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${org.hibernate.jpamodelgen.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version>
</dependency>
</dependencies>

<build>
<!-- Generate compiled stuff in the folder used for developing mode -->
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

<plugins>

<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.3.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>i18n</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>jgkgwtclasscastissue.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
<i18nMessagesBundle>com.gs.client.Messages</i18nMessagesBundle>
</configuration>
</plugin>

<!-- Copy static web files before executing gwt:run -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
<configuration>
<webappDirectory>${webappDirectory}</webappDirectory>
</configuration>
</plugin>

</plugins>
</build>
</project>

不清楚问题出在哪里。有什么建议吗?

最佳答案

在这里发现同样的问题:Exception in GWT Dev Mode + Spring 3.1 + Hibernate 4.0.1

它来自 Hibernate 上的类加载器问题,该问题似乎与 GWT/jetty shell 模式不兼容。该错误在 Hibernate 上仍然存在,但您可以应用补丁(请参阅 https://hibernate.onjira.com/browse/HHH-7084)

关于java - ClassCastException InjectedDataSourceConnectionProvider Spring 3.1.0、Hibernate 4、JPA EntityManagerFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9318378/

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