java – 使用Hibernate进行WildFly迁移的JBoss as7

我尝试从JBoss AS 7迁移到Wildfly 8.2.我真的遇到了hibernate的问题.

我正在使用maven与依赖项:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>4.2.0.Final</version>
</dependency>

<dependency>
  <groupId>org.hibernate.javax.persistence</groupId>
  <artifactId>hibernate-jpa-2.0-api</artifactId>
  <version>1.0.1.Final</version>
</dependency>

当我启动我的应用程序时,女巫正在AS 7中工作,我在wildfly中得到错误:

10:08:11,485 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 53) MSC000001: Failed to start service jboss.persistenceunit."com.haslerrail.MyDatabase.web.war#MyDatabase": org.jboss.msc.service.StartException in service jboss.persistenceunit."com.haslerrail.MyDatabase.web.war#MyDatabase": javax.persistence.PersistenceException: [PersistenceUnit: MyDatabase] Unable to build Hibernate SessionFactory
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
      at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_65]
      at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_65]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_65]
      at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_65]
      at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyDatabase] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1239) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:855) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
      at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
      at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
      ... 8 more
Caused by: org.hibernate.AnnotationException: Attribute [com.haslerrail.MyDatabase.server.db.entity.Widget.type] was annotated as enumerated, but its java type is not an enum [java.lang.String]
      at org.hibernate.cfg.annotations.SimpleValueBinder.setType(SimpleValueBinder.java:257) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.annotations.PropertyBinder.makePropertyAndValue(PropertyBinder.java:195) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:216) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2241) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:963) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:796) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) [hibernate-core-4.3.7.Final.jar:4.3.7.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852) [hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
      ... 13 more

我试图找到hibernate和wildfly的任何文档但是https://docs.jboss.org/author/display/WFLY8/Hibernate上的文档是空的!!!!

有没有人有从AS 7迁移到Wildfly和hibernate的经验?我需要调整什么?

解决方法:

Hibernate的容器版本优先于Java EE conatiner中的应用程序打包版本.因而错误.

要避免这种情况,您需要显式控制类加载并排除容器库.阅读here

基本上,您需要提供一个jboss-deployment-structure.xml,以便对依赖项进行细粒度控制.

例如:

    <jboss-deployment-structure>
        <deployment>
            <exclusions>
                <!-- Exclude container version of hibernate. By default its version 4, we want 
                    bundled version to load -->
                <module name="org.hibernate" slot="main" />
            </exclusions>
        </deployment>
    </jboss-deployment-structure>
上一篇:java-如何在jboss7.1.1服务器中将jboss时区IST(Asia / Calcutta)更改为EST(America / New_York)


下一篇:java-从Mac OS中的代码检索环境变量值