WildFly 10.0 中的 Hibernate 版本不匹配
Hibernate version mismatch in WildFly 10.0
我有2个项目,一个是普通的java项目(有maven):core
,另一个是非maven动态web项目:webapi
。后者充当 core
.
之上的休息层
core
使用休眠没有任何问题。它定义 persistence.xml
(在 src/META-INF/
内)如下:
<?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
添加到 "Java Build Path" 和 webapi
的 "Deployment Assembly"。由于我使用的是 SQL 服务器,sqljdbc42.jar
也被添加到 webapi
的 "Deployment Assembly"。
但是,当我尝试在 WildFly 10.0 中部署 webapi
时,休眠实体管理器未正确实例化。我主要怀疑 core
和 webapi
中的 hibernate-core 版本不匹配。 core
使用 hibernate-core 5.2.4.Final
,而对于 webapi
,它来自 WildFly 运行时,即 5.0.7.Final
。这可以从下面的日志中看出:
core
日志:
[HibernateManager.:19] - Trying to create entityManager for persistence-unit: app
[LogHelper.logPersistenceUnitInformation:31] - HHH000204: Processing PersistenceUnitInfo [
name: app
...]
[Version.logVersion:45] - HHH000412: Hibernate Core {5.2.4.Final}
[Environment.:213] - HHH000206: hibernate.properties not found
[Environment.buildBytecodeProvider:318] - HHH000021: Bytecode provider name : javassist
[JavaReflectionManager.:66] - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[DriverManagerConnectionProviderImpl.configure:70] - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
[DriverManagerConnectionProviderImpl.buildCreator:126] - HHH10001005: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost;databaseName=AppDb]
[DriverManagerConnectionProviderImpl.buildCreator:135] - HHH10001001: Connection properties: {user=****, password=****}
[DriverManagerConnectionProviderImpl.buildCreator:140] - HHH10001003: Autocommit mode: false
[PooledConnections.:41] - HHH000115: Hibernate connection pool size: 20 (min=1)
[Dialect.:153] - HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
[Version.:30] - HV000001: Hibernate Validator 5.2.3.Final
[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] - Created entityManager for persistence-unit: app
[QueryTranslatorFactoryInitiator.initiateService:47] - HHH000397: Using ASTQueryTranslatorFactory
webapi
日志:
[org.jboss.as.jpa] (MSC service thread 1-2) WFLYJPA0002: Read persistence.xml for 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 Thread Pool -- 29) HHH000204: Processing PersistenceUnitInfo [
name: app
...]
[org.hibernate.Version] (ServerService Thread Pool -- 29) HHH000412: Hibernate Core {5.0.7.Final}
[org.hibernate.cfg.Environment] (ServerService Thread Pool -- 29) HHH000206: hibernate.properties not found
[org.hibernate.cfg.Environment] (ServerService Thread Pool -- 29) HHH000021: Bytecode provider name : javassist
[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 Thread Pool -- 29) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[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 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 Thread Pool -- 29) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'webapi.war#app'
[org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 29) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
[org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 29) Envers integration enabled? : true
[org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 29) HV000001: Hibernate Validator 5.2.3.Final
[org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 29) HHH000228: Running hbm2ddl schema update
[org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl] (ServerService Thread Pool -- 29) HHH000262: Table not found: Anythings
[org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl] (ServerService Thread Pool -- 29) HHH000262: Table not found: Somethings
[org.wildfly.extension.undertow] (ServerService Thread Pool -- 28) WFLYUT0021: Registered web context: /webapi
[org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "webapi.war" (runtime-name : "webapi.war")
如何纠正?
这可以通过在 Wildfly 中更改 Hibernate 核心版本来解决。为此,请像这样更改 META-INF/persistence.xml 文件:
<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" />
礼貌 link :http://in.relation.to/2016/07/07/updating-hibernate-orm-in-wildfly/
我有2个项目,一个是普通的java项目(有maven):core
,另一个是非maven动态web项目:webapi
。后者充当 core
.
core
使用休眠没有任何问题。它定义 persistence.xml
(在 src/META-INF/
内)如下:
<?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
添加到 "Java Build Path" 和 webapi
的 "Deployment Assembly"。由于我使用的是 SQL 服务器,sqljdbc42.jar
也被添加到 webapi
的 "Deployment Assembly"。
但是,当我尝试在 WildFly 10.0 中部署 webapi
时,休眠实体管理器未正确实例化。我主要怀疑 core
和 webapi
中的 hibernate-core 版本不匹配。 core
使用 hibernate-core 5.2.4.Final
,而对于 webapi
,它来自 WildFly 运行时,即 5.0.7.Final
。这可以从下面的日志中看出:
core
日志:[HibernateManager.:19] - Trying to create entityManager for persistence-unit: app
[LogHelper.logPersistenceUnitInformation:31] - HHH000204: Processing PersistenceUnitInfo [ name: app ...]
[Version.logVersion:45] - HHH000412: Hibernate Core {5.2.4.Final}
[Environment.:213] - HHH000206: hibernate.properties not found
[Environment.buildBytecodeProvider:318] - HHH000021: Bytecode provider name : javassist
[JavaReflectionManager.:66] - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[DriverManagerConnectionProviderImpl.configure:70] - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
[DriverManagerConnectionProviderImpl.buildCreator:126] - HHH10001005: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost;databaseName=AppDb]
[DriverManagerConnectionProviderImpl.buildCreator:135] - HHH10001001: Connection properties: {user=****, password=****}
[DriverManagerConnectionProviderImpl.buildCreator:140] - HHH10001003: Autocommit mode: false
[PooledConnections.:41] - HHH000115: Hibernate connection pool size: 20 (min=1)
[Dialect.:153] - HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
[Version.:30] - HV000001: Hibernate Validator 5.2.3.Final
[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] - Created entityManager for persistence-unit: app
[QueryTranslatorFactoryInitiator.initiateService:47] - HHH000397: Using ASTQueryTranslatorFactory
webapi
日志:[org.jboss.as.jpa] (MSC service thread 1-2) WFLYJPA0002: Read persistence.xml for 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 Thread Pool -- 29) HHH000204: Processing PersistenceUnitInfo [ name: app ...]
[org.hibernate.Version] (ServerService Thread Pool -- 29) HHH000412: Hibernate Core {5.0.7.Final}
[org.hibernate.cfg.Environment] (ServerService Thread Pool -- 29) HHH000206: hibernate.properties not found
[org.hibernate.cfg.Environment] (ServerService Thread Pool -- 29) HHH000021: Bytecode provider name : javassist
[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 Thread Pool -- 29) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[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 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 Thread Pool -- 29) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'webapi.war#app'
[org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 29) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
[org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 29) Envers integration enabled? : true
[org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 29) HV000001: Hibernate Validator 5.2.3.Final
[org.hibernate.tool.hbm2ddl.SchemaUpdate] (ServerService Thread Pool -- 29) HHH000228: Running hbm2ddl schema update
[org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl] (ServerService Thread Pool -- 29) HHH000262: Table not found: Anythings
[org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl] (ServerService Thread Pool -- 29) HHH000262: Table not found: Somethings
[org.wildfly.extension.undertow] (ServerService Thread Pool -- 28) WFLYUT0021: Registered web context: /webapi
[org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "webapi.war" (runtime-name : "webapi.war")
如何纠正?
这可以通过在 Wildfly 中更改 Hibernate 核心版本来解决。为此,请像这样更改 META-INF/persistence.xml 文件:
<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" />
礼貌 link :http://in.relation.to/2016/07/07/updating-hibernate-orm-in-wildfly/