我刚把我的项目的hibernate版本升级到了5.0.0.FINAL。但是我发现我收到了这个警告。我想摆脱它。我不知道它是否会影响我的应用程序。
2015-08-24 14:29:22.235 WARN --- [ main] org.hibernate.orm.deprecation : HHH90000003: Use of DOM4J entity-mode is considered deprecated
由于我从未显式使用实体模式,所以我在网上搜索了一下,但几乎没有关于它的信息。这是EntityMode枚举。由于不再有DOM4J
模式,我怀疑如果我继续在5.0.0版本中使用hibernate,可能会在生产中出现错误。
我还在使用hibernate的envers。如果我禁用envers,警告也会消失。我同时使用spring和hibernate和envers。以下是它们的版本。
<spring.version>4.2.0.RELEASE</spring.version>
<hibernate.version>5.0.0.Final</hibernate.version>
<hibernate.envers.version>5.0.0.Final</hibernate.envers.version>
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
<project.java.version>1.8</project.java.version>
这是我的hibernate-jpa配置。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="commonsEntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="commonDataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.ejb.interceptor">com.examples.dao.utils.AbstractEntityInterceptor</prop>
<!--<prop key="hibernate.listeners.envers.autoRegister">false</prop>-->
<prop key="hibernate.implicit_naming_strategy">org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl</prop>
<prop key="hibernate.physical_naming_strategy">org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.showSql">${hibernate.showSql}</prop>
<prop key="hibernate.formatSql">${hibernate.formatSql}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="org.hibernate.envers.audit_table_suffix">${org.hibernate.envers.audit_table_suffix}</prop>
<prop key="javax.persistence.sharedCache.mode">${javax.persistence.sharedCache.mode}</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.examples.entity</value>
</list>
</property>
</bean>
<bean id="commonsTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="commonsEntityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="commonsTransactionManager"/>
<context:component-scan base-package="com.examples.dao.*"/>
</beans>
这里是一个实体的例子。
@Entity
@Table(name = "T_USER")
@Access(AccessType.FIELD)
@Audited
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "C_USERNAME", unique = true)
private String username;
@Column(name = "C_PASSWORD")
private String password;
@Column(name = "C_EMAIL")
private String email;
// Getters && Setters etc
}
更新
我在github上创建了一个项目,展示了这种行为。经过一些调试,我发现警告信息是在ModelBinder#L2441上创建的。
以下是示例代码:
public class ModelBinder
...
private void bindProperty(
MappingDocument mappingDocument,
AttributeSource propertySource,
Property property) {
property.setName( propertySource.getName() );
if ( StringHelper.isNotEmpty( propertySource.getName() ) ) {
// Here is the line that print outs the log I was mentioned
DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport();
}
...
}
}
当我查看
mappingDocument.getOrigin()
的值时,它是Origin(name=envers,type=OTHER)
。因此,我仍然怀疑envers引起了这个警告。顺便说一下,如果您删除
@Audit
注释或使用我提到的属性,则此警告仍将消失。
POJO
模式。但是你可以通过@Tuplizer
注释或<tuplizer />
标签来覆盖它。但是由Envers创建的实体默认使用DOM
。我在日志中看到与Envers实体大小相同数量的警告。但是我无法覆盖Envers实体模式。您可以在hibernate文档中找到有关tupilizer的额外信息。 - bhdrkn