Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of "HHH90000003: Use of DOM4J entity-mode is considered deprecated"

I just upgraded my project's hibernate version to 5.0.0.FINAL. But than I realise that, I am getting this warning. And I want to get rid of it. I don't know if it will effect my application or not.

2015-08-24 14:29:22.235  WARN   --- [           main] org.hibernate.orm.deprecation            : HHH90000003: Use of DOM4J entity-mode is considered deprecated

Since I never used entity-mode explicitly, I searched online but there is almost no information about it. Here is the EntityMode enum. Since, there is no DOM4J mode any more, I am suspecting that I might get an error in production if I continue to use hibernate in version 5.0.0.

I am also using envers with hibernate. If I disable envers the warning also disappears.I am using spring alongside with hibernate and envers. And here is the versions of them.

<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>

And here is my hibernate-jpa configuration.

<?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>

And here is an example entity.

@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
}

Update

I created a project on github that demonstrates this behaviour. After debugging a little, I found out that the warning message is created on ModelBinder#L2441.

Here is the sample code:

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();
        }
...
    }
}

And when I looked into the value of mappingDocument.getOrigin(), It was Origin(name=envers,type=OTHER). So I still suspecting that envers is causing this warning.

By the way, If you remove @Audit annotation, or use the property I was mentioned, this warning still disappears.

like image 700
bhdrkn Avatar asked Aug 24 '15 11:08

bhdrkn


2 Answers

I think that those messages are cause by bug in ModelBinder. Instead of getName should be getXmlNodeName. I've reported that issue and I hope that this will be fixed in next release. Anyway, besides extra log lines, there are no any other consequences.

like image 59
Cedomir Igaly Avatar answered Nov 03 '22 21:11

Cedomir Igaly


I use the same env just like @bhdrkn

<!-- Jpa Entity Manager 配置 -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database">
                <bean factory-method="getDatabase" class="net.gelif.core.persistence.Hibernates">
                    <constructor-arg ref="dataSource"/>
                </bean>
            </property>
        </bean>
    </property>
    <property name="packagesToScan">
        <array>
            <value>net.gelif.**.entity</value>
        </array>
    </property>
    <property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
    <property name="jpaProperties">
        <props>
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).HBM2DDL_AUTO}">update</prop><!-- hibernate.hbm2ddl.auto -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).DEFAULT_ENTITY_MODE}">pojo</prop><!-- hibernate.default_entity_mode -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).CURRENT_SESSION_CONTEXT_CLASS}">thread</prop><!-- hibernate.current_session_context_class -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).CACHE_REGION_FACTORY}">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop><!-- hibernate.cache.region.factory_class -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).USE_SECOND_LEVEL_CACHE}">true</prop><!-- hibernate.cache.use_second_level_cache -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).USE_QUERY_CACHE}">true</prop><!-- hibernate.cache.use_query_cache -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).SHOW_SQL}">false</prop><!-- hibernate.show_sql -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).MAX_FETCH_DEPTH}">3</prop><!-- hibernate.max_fetch_depth -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS}">false</prop><!-- hibernate.discriminator.ignore_explicit_for_joined -->
            <prop key="#{T(org.hibernate.cfg.AvailableSettings).USE_NEW_ID_GENERATOR_MAPPINGS}">true</prop><!-- hibernate.id.new_generator_mappings -->
            <prop key="#{T(org.hibernate.jpa.AvailableSettings).VALIDATION_MODE}">none</prop><!-- javax.persistence.validation.mode -->
            <prop key="#{T(org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory).NET_SF_EHCACHE_CONFIGURATION_RESOURCE_NAME}">cache/ehcache-hibernate-local.xml</prop><!-- net.sf.ehcache.configurationResourceName -->

            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).AUDIT_TABLE_PREFIX}"></prop><!-- org.hibernate.envers.audit_table_prefix 配置数据修改记录表名的前缀规则  默认值:空 -->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).AUDIT_TABLE_SUFFIX}">_audit</prop><!-- org.hibernate.envers.audit_table_suffix 配置数据修改记录表名的后缀规则  默认值:_AUD -->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).REVISION_FIELD_NAME}">revision</prop><!-- org.hibernate.envers.revision_field_name 配置数据修改记录表版本号字段名  默认值: REV -->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).REVISION_TYPE_FIELD_NAME}">revision_type</prop><!-- org.hibernate.envers.revision_type_field_name 配置数据修改记录表修改类型字段名  默认值: REVTYPE  . 0表示新增加,1修改 2删除 -->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).REVISION_ON_COLLECTION_CHANGE}">true</prop><!-- org.hibernate.envers.revision_on_collection_change 配置是否支持关联表修改时记录修改记录  默认值:true-->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).DO_NOT_AUDIT_OPTIMISTIC_LOCKING_FIELD}">true</prop><!-- org.hibernate.envers.do_not_audit_optimistic_locking_field 配置是否不对乐观锁字段修改时记录修改记录,即使用(@Version)字段  默认值:true-->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).STORE_DATA_AT_DELETE}">true</prop><!-- org.hibernate.envers.store_data_at_delete 配置是否在删除操作时,只保存id值还是全部的值。 默认值:false 只记录id-->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).DEFAULT_SCHEMA}"></prop><!-- org.hibernate.envers.default_schema 配置数据修改记录表的schema 默认值:null-->
            <prop key="#{T(org.hibernate.envers.configuration.EnversSettings).DEFAULT_CATALOG}"></prop><!-- org.hibernate.envers.default_catalog 配置数据修改记录表的catalog 默认值:null-->
        </props>
    </property>
</bean>

<!-- Spring Data Jpa配置, 扫描base-package下所有继承于Repository<T,ID>的接口 -->
<jpa:repositories base-package="net.gelif.ems.**.dao.**" repository-impl-postfix="Impl" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="jpaTransactionManager"/>

<!-- 事务管理器配置, Jpa单数据源事务 -->
<bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="jpaTransactionManager" proxy-target-class="true"/>

and while I removed the hibernate envers setting and @Audit from entities, these warning disappeared.

like image 41
geewit Avatar answered Nov 03 '22 20:11

geewit