7

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.

bhdrkn
  • 6,244
  • 5
  • 35
  • 42
  • I don't think envers or spring has anything to do with this -- I have exactly the same issue after ugprading from Hibernate 4 to 5, and my project is a bare-bones application using just native Hibernate on its own, with XML mapping files. – David Sep 08 '15 at 08:37
  • 1
    @David as far as I know on default hibernate uses `POJO` mode. But you can override it either `@Tuplizer` annotation or `` tag. But entities created by envers uses `DOM` as default. And I am seeing as same amount of warning on log as envers entity size. But I cannot override envers entity-mode. You can find extra information about tupilizer on [hibernate documentation](https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/persistent-classes.html#example-specify-custom-tuplizer-ann). – bhdrkn Sep 08 '15 at 09:07
  • To be clear, Envers uses the MAP entity mode, not the (removed) DOM4J entity mode. – Steve Ebersole Sep 10 '15 at 14:46
  • @SteveEbersole Then, why the warning messages are removed when I am disabled the envers? Could you point out the source code that proves envers is using MAP? – bhdrkn Sep 10 '15 at 15:26
  • If I had to guess, maybe Envers is specifying embed-xml in the XML it generates? You'd have to look. But regardless, I *assure* you, Envers uses EntityMode.MAP, not EntityMode.DOM4J – Steve Ebersole Sep 10 '15 at 22:25
  • @SteveEbersole After some debugging, data still points out that envers is causing this problem. But it seams to me, I can ignore this warning. And also, since you are authored `ModelBinder`, I want to ask you this "why there is such a log?" (I try to ask politely, sorry for my english). Concluding `DOM` usage just by looking `propertySource.getName()` is seems irrelevant to me. Is this some kind of mis-logging or bug? – bhdrkn Sep 11 '15 at 21:47
  • 2
    I'm not using Envers at all, and I still get this deprecation warning. I'm using separate XML mapping documents (no annotations). Have XML mapping documents been deprecated? Or is this test just being very over-eager? – David Sep 14 '15 at 14:18

3 Answers3

6

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.

1

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.

geewit
  • 11
  • 1
  • I use customized hibernate-envers settings like this,there is still "HHH90000003: Use of DOM4J entity-mode is considered deprecated" warnings. @Entity @RevisionEntity(GlobalRevisionListener.class) @Table(name = "global_revisions") public class GlobalRevisionEntity { ... } – geewit Oct 08 '15 at 02:09
  • when I debug, I found AttributeSource propertySource is implements by CompositeIdentifierSingularAttributeSourceManyToOneImpl and the "getXmlNodeName" method return not null. – geewit Oct 08 '15 at 02:19
  • All the "getXmlNodeName" method return "revision". – geewit Oct 08 '15 at 02:26
0

This problem is fixed a new hibernate version as released here: with http://in.relation.to/2015/09/30/hibernate-orm-502-final-release/. See https://hibernate.atlassian.net/browse/HHH-10115 After an upgrade the problem should be solved.