java - 如何摆脱 "HHH90000003: Use of DOM4J entity-mode is considered deprecated"

标签 java spring hibernate jpa hibernate-envers

我刚刚将项目的 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

由于我从来没有明确地使用过entity-mode,所以我在网上搜索了但几乎没有关于它的信息。这是 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 注释,或使用我提到的属性,此警告仍然会消失。

最佳答案

我认为这些消息是由 ModelBinder 中的错误引起的。而不是 getName 应该是 getXmlNodeName。我已经报告了这个问题,我希望这将在下一个版本中得到修复。无论如何,除了额外的日志行,没有任何其他后果。

关于java - 如何摆脱 "HHH90000003: Use of DOM4J entity-mode is considered deprecated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32181529/

相关文章:

Java客户端服务器应用程序,无法发送ArrayList

java - Spring JSON反序列化字符限制

java - @RequestMapping( Produces = "application/json;charset=utf-8") 是否会阻止 jsonp 请求?

java - hibernate中M-M关系中的记录顺序不正确

linux - NoSuchMethodError 仅在 Linux 上

java - Android 4.0 WebView.loadURL 奇怪

java - 奇怪且令人恼火的 struts 问题!

Java线程问题?

java - 在静态方法中使用注入(inject)的 bean 的正确方法是什么?

java - 在 Hibernate 中加载类型实体