WildFly 10.0中的Hibernate版本不匹配 [英] Hibernate version mismatch in WildFly 10.0
问题描述
我有2个项目,一个是普通的Java项目(带有Maven): core
,另一个是非Maven动态Web项目: webapi
.后者充当 core
顶部的休息层.
I have 2 projects, one is a normal java project (with maven): core
, and the other is non-maven dynamic web project: webapi
. The later acts as a rest layer on top of core
.
核心
使用休眠模式没有任何问题.它定义 persistence.xml
(在 src/META-INF/
内部)如下:
core
uses hibernate without any problem. It defines the persistence.xml
(inside src/META-INF/
) as follows:
<?xml version="1.0" encoding="utf-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="app" transaction-type="RESOURCE_LOCAL">
<class>data.entities.Anything</class>
<class>data.entities.Something</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost;databaseName=AppDb"></property>
<property name="javax.persistence.jdbc.user" value="****"></property>
<property name="javax.persistence.jdbc.password" value="****"></property>
<property name="hibernate.default_schema" value="dbo"></property>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"></property>
<property name="hibernate.hbm2ddl.auto" value="update"></property>
</properties>
</persistence-unit>
</persistence>
webapi
使用 core
并尝试将 core
的功能作为服务公开.我已经将 core
添加到了 webapi
的"Java构建路径"和部署程序集"中.当我使用SQL Server时,还将 sqljdbc42.jar
添加到 webapi
的部署程序集"中.
webapi
uses core
and try to expose core
's functionality as service. I have added core
to both "Java Build Path", and "Deployment Assembly" of webapi
. As I am using SQL Server, sqljdbc42.jar
is also added to "Deployment Assembly" of webapi
.
但是,当我尝试在WildFly 10.0中部署 webapi
时,休眠实体管理器未正确实例化.我主要怀疑这里的 core
和 webapi
中的hibernate-core版本不匹配. core
使用 hibernate-core 5.2.4.Final
,而对于 webapi
,它来自WildFly运行时,即 5.0.7.最终
.这可以从下面的日志中看到:
However, when I try to deploy webapi
in WildFly 10.0, the hibernate entity manager is not instantiated properly. My primary suspect here the version mismatch of hibernate-core in core
, and webapi
. core
uses hibernate-core 5.2.4.Final
, whereas for webapi
it is coming from WildFly runtime, which is 5.0.7.Final
. This can be seen from the logs below:
-
核心
日志:
[HibernateManager.:19]-尝试为持久性单元:应用
[HibernateManager.:19] - Trying to create entityManager for persistence-unit: app
[LogHelper.logPersistenceUnitInformation:31]-HHH000204:处理PersistenceUnitInfo [名称:app...]
[LogHelper.logPersistenceUnitInformation:31] - HHH000204: Processing PersistenceUnitInfo [ name: app ...]
[Version.logVersion:45]- HHH000412:Hibernate Core {5.2.4.Final}
[Version.logVersion:45] - HHH000412: Hibernate Core {5.2.4.Final}
[环境:213]-HHH000206:找不到hibernate.properties
[Environment.:213] - HHH000206: hibernate.properties not found
[Environment.buildBytecodeProvider:318]-HHH000021:字节码提供者名称:javassist
[Environment.buildBytecodeProvider:318] - HHH000021: Bytecode provider name : javassist
[JavaReflectionManager.:66]-HCANN000001:Hibernate Commons注释{5.0.1.Final}
[JavaReflectionManager.:66] - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[DriverManagerConnectionProviderImpl.configure:70]-HHH10001002:使用Hibernate内置连接池(不适用于生产!)
[DriverManagerConnectionProviderImpl.configure:70] - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
[DriverManagerConnectionProviderImpl.buildCreator:126]-HHH10001005:在URL [jdbc:sqlserver://localhost; databaseName = AppDb]使用驱动程序[com.microsoft.sqlserver.jdbc.SQLServerDriver]
[DriverManagerConnectionProviderImpl.buildCreator:126] - HHH10001005: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost;databaseName=AppDb]
[DriverManagerConnectionProviderImpl.buildCreator:135]-HHH10001001:连接属性:{user = ****,密码= ****}
[DriverManagerConnectionProviderImpl.buildCreator:135] - HHH10001001: Connection properties: {user=****, password=****}
[DriverManagerConnectionProviderImpl.buildCreator:140]-HHH10001003:自动提交模式:false
[DriverManagerConnectionProviderImpl.buildCreator:140] - HHH10001003: Autocommit mode: false
[PooledConnections.:41]-HHH000115:休眠连接池大小:20(最小= 1)
[PooledConnections.:41] - HHH000115: Hibernate connection pool size: 20 (min=1)
[方言:153]-HHH000400:使用方言:org.hibernate.dialect.SQLServer2008Dialect
[Dialect.:153] - HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
[版本:30]-HV000001:休眠验证器5.2.3.Final
[Version.:30] - HV000001: Hibernate Validator 5.2.3.Final
[DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection:47]-HHH10001501:从JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@19ccca5]获得的连接不是(非JTA自动)Dcom执行的模式;连接本地事务"将被提交,并且连接将被设置为自动提交模式.
[DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection:47] - HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@19ccca5] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
[HibernateManager.:22]-为持久性单元:app创建了objectManager
[HibernateManager.:22] - Created entityManager for persistence-unit: app
[QueryTranslatorFactoryInitiator.initiateService:47]-HHH000397:使用ASTQueryTranslatorFactory
[QueryTranslatorFactoryInitiator.initiateService:47] - HHH000397: Using ASTQueryTranslatorFactory
webapi
日志:
[org.jboss.as.jpa](MSC服务线程1-2)WFLYJPA0002:读取应用程序的persistence.xml
[org.jboss.as.jpa] (MSC service thread 1-2) WFLYJPA0002: Read persistence.xml for app
[org.jboss.as.jpa](ServerService线程池-29)WFLYJPA0010:启动持久性单元(第1阶段,共2阶段)服务'webapi.war#app'
[org.jboss.as.jpa] (ServerService Thread Pool -- 29) WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service 'webapi.war#app'
[org.hibernate.jpa.internal.util.LogHelper](ServerService线程池-29)HHH000204:处理PersistenceUnitInfo [名称:app...]
[org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 29) HHH000204: Processing PersistenceUnitInfo [ name: app ...]
[org.hibernate.Version](ServerService线程池-29) HHH000412:Hibernate Core {5.0.7.Final}
[org.hibernate.Version] (ServerService Thread Pool -- 29) HHH000412: Hibernate Core {5.0.7.Final}
[org.hibernate.cfg.Environment](ServerService线程池-29)HHH000206:找不到hibernate.properties
[org.hibernate.cfg.Environment] (ServerService Thread Pool -- 29) HHH000206: hibernate.properties not found
[org.hibernate.cfg.Environment](ServerService线程池-29)HHH000021:字节码提供程序名称:javassist
[org.hibernate.cfg.Environment] (ServerService Thread Pool -- 29) HHH000021: Bytecode provider name : javassist
[org.hibernate.orm.deprecation](ServerService线程池-29)HHH90000001:发现使用了不推荐使用的设置来指定扫描程序[hibernate.ejb.resource_scanner];使用[hibernate.archive.scanner]代替
[org.hibernate.orm.deprecation] (ServerService Thread Pool -- 29) HHH90000001: Found usage of deprecated setting for specifying Scanner [hibernate.ejb.resource_scanner]; use [hibernate.archive.scanner] instead
[org.hibernate.annotations.common.Version](ServerService线程池-29)HCANN000001:Hibernate Commons注释{5.0.1.Final}
[org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 29) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[org.jboss.as.connector.deployers.jdbc](MSC服务线程1-5)WFLYJCA0004:部署JDBC兼容驱动程序类com.microsoft.sqlserver.jdbc.SQLServerDriver(版本6.0)
[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0004: Deploying JDBC-compliant driver class com.microsoft.sqlserver.jdbc.SQLServerDriver (version 6.0)
[org.jboss.as.connector.deployers.jdbc](MSC服务线程1-5)WFLYJCA0018:启动了具有驱动程序名称= webapi.war_com.microsoft.sqlserver.jdbc.SQLServerDriver_6_0的驱动程序服务
[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0018: Started Driver service with driver-name = webapi.war_com.microsoft.sqlserver.jdbc.SQLServerDriver_6_0
[org.jboss.as.jpa](ServerService线程池-29)WFLYJPA0010:启动持久性单元(第2阶段,共2阶段)服务'webapi.war#app'
[org.jboss.as.jpa] (ServerService Thread Pool -- 29) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'webapi.war#app'
[org.hibernate.dialect.Dialect](ServerService线程池-29)HHH000400:使用方言:org.hibernate.dialect.SQLServer2008Dialect
[org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 29) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
[org.hibernate.envers.boot.internal.EnversServiceImpl](ServerService线程池-29)启用了Envers集成吗?:正确
[org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 29) Envers integration enabled? : true
[org.hibernate.validator.internal.util.Version](ServerService线程池-29)HV000001:Hibernate Validator 5.2.3.Final
[org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 29) HV000001: Hibernate Validator 5.2.3.Final
[org.hibernate.tool.hbm2ddl.SchemaUpdate](服务器服务线程池-29)HHH000228:运行hbm2ddl模式更新
[org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 29) HHH000228: Running hbm2ddl schema update
[org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl](ServerService线程池-29)HHH000262:找不到表:一切
[org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl](ServerService线程池-29)HHH000262:找不到表:某些东西
[org.wildfly.extension.undertow](ServerService线程池-28)WFLYUT0021:注册的Web上下文:/webapi
[org.wildfly.extension.undertow] (ServerService Thread Pool -- 28) WFLYUT0021: Registered web context: /webapi
[org.jboss.as.server](DeploymentScanner线程-1)WFLYSRV0010:部署了"webapi.war"(运行时名称:"webapi.war")
[org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "webapi.war" (runtime-name : "webapi.war")
该如何纠正?
推荐答案
这可以通过在Wildfly中更改Hibernate内核的版本来解决.为此,请像这样更改您的META-INF/persistence.xml文件:
This can be solved by changing the version of your Hibernate core in Wildfly. In order to do so, change your META-INF/persistence.xml file like this :
<properties>
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2" />
...
</properties>
要添加一些微型版本:
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2.4.Final" />
礼貌链接: http://in.relation.to/2016/07/07/updating-hibernate-orm-in-wildfly/
这篇关于WildFly 10.0中的Hibernate版本不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!