# Hibernate Envers does not work with Any type

**URL:** <https://discourse.hibernate.org/t/hibernate-envers-does-not-work-with-any-type/7670>\
**Category:** Hibernate ORM\
**Created:** [May 22, 2023, 7:36am UTC](https://discourse.hibernate.org/t/hibernate-envers-does-not-work-with-any-type/7670 "2023-05-22T07:36:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahir\_Palos](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mahir_palos/32/2433_2.png) [@Mahir\_Palos](https://discourse.hibernate.org/u/Mahir_Palos)\
**Post date:** [May 22, 2023, 7:36am UTC](https://discourse.hibernate.org/t/hibernate-envers-does-not-work-with-any-type/7670/1 "2023-05-22T07:36:55Z")

</div>

Hibernate Envers appears not to work with org.hibernate.type.AnyType.  
When [@Any](https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#associations-any) hibernate annotation is used to describe specific polymorphic mapping use case, auditing with Envers does not work out of the box.  
With entity field defined as:

```plaintext
    @Any(
            metaDef = "PartyMetaDef",
            metaColumn = @Column( name = "dest_type" )
    )
    @JoinColumn( name = "dest_id" )
    private Party destination;

```

where Party is abstract class and finally comes in one of two flavors.  
Actual party type is decided via PartyMetaDef, and ends up in dest\_type (CHAR) column in database.  
Actual parent entity id is stored in dest\_id (LONG).

Now, for some reason Envers cannot work with this and gives

```
org.hibernate.MappingException: Type not supported for auditing: org.hibernate.type.AnyType, on entity MyEntity, property 'destination'.
at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.throwUnsupportedTypeException(AuditMetadataGenerator.java:764) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]
	at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addValueInFirstPass(AuditMetadataGenerator.java:212) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]
	at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addValue(AuditMetadataGenerator.java:316) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]
	at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addProperties(AuditMetadataGenerator.java:350) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]

```

Hibernate and Envers versions are both 5.4.32.Final

PartyMetaDef is defined as:

```plaintext
@AnyMetaDefs(
        @AnyMetaDef( name= "PartyMetaDef", metaType = "string", idType = "long",
                metaValues = {
                        @MetaValue(value = "C", targetEntity = Contact.class),
                        @MetaValue(value = "W", targetEntity = Warehouse.class)
                }
        )
)

```

Both Contact and Warehouse inherit from Party abstract class.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 22, 2023, 7:56am UTC](https://discourse.hibernate.org/t/hibernate-envers-does-not-work-with-any-type/7670/2 "2023-05-22T07:56:50Z")

</div>

Try updating to the latest Hibernate 5.6, as 5.4 is not supported.

---

<div class="post-metadata">

**Author:** ![Mahir\_Palos](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mahir_palos/32/2433_2.png) [@Mahir\_Palos](https://discourse.hibernate.org/u/Mahir_Palos)\
**Post date:** [May 26, 2023, 3:02am UTC](https://discourse.hibernate.org/t/hibernate-envers-does-not-work-with-any-type/7670/3 "2023-05-26T03:02:31Z")

</div>

Thanks for the response.  
Did that, upgraded all services to use Hibernate 5.6.15. but message is still the same:

org.hibernate.MappingException: Type not supported for auditing: org.hibernate.type.AnyType, on entity…

It looks like a well formatted message i.e. maybe given feature is indeed missing?  
Helpful info would be if there are any ways to circumvent this or info on future upgrades to deal with auditing polymorphic relation.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 26, 2023, 6:46am UTC](https://discourse.hibernate.org/t/hibernate-envers-does-not-work-with-any-type/7670/4 "2023-05-26T06:46:13Z")

</div>

> maybe given feature is indeed missing?

Maybe, yeah. Try searching in the issue tracker for feature requests. But either way, if you want new features, you’d have to upgrade to Hibernate 6.3 then as that is the only version which receives new features now.

> Helpful info would be if there are any ways to circumvent this or info on future upgrades to deal with auditing polymorphic relation.

You can try to model the association differently for the purpose of auditing e.g.

```auto
@Column(name = "dest_type")
Character destType;
@Column(name = "dest_id")
Long destId;

```

and just keep that in sync with the `destination` mapping
