Skip to content

Commit

Permalink
[wip] Fix Envers compatibility with ImmutableType
Browse files Browse the repository at this point in the history
Envers expects (simple) audited types to implement the BasicType
interface. This commit changes The ImmutableType to implement BasicType
rather than Type.

The commit is work in progress: It only applies the change to
hibernate-types-55 as a template. If the change is OK, it will be
applied to other hibernate-types-* as well.

Resolves: vladmihalcea#463
  • Loading branch information
msdousti committed Aug 1, 2022
1 parent 697c7a6 commit c8876e8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
7 changes: 7 additions & 0 deletions hibernate-types-55/pom.xml
Expand Up @@ -24,6 +24,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>${hibernate.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Expand Up @@ -101,13 +101,13 @@ private HibernateTypesContributor contributeType(TypeContributions typeContribut
return this;
}

private HibernateTypesContributor contributeType(TypeContributions typeContributions, ImmutableType<?> type) {
typeContributions.contributeType(type);
return this;
}

private HibernateTypesContributor contributeType(TypeContributions typeContributions, UserType type) {
if(type instanceof ImmutableType) {
ImmutableType immutableType = (ImmutableType) type;
typeContributions.contributeType(immutableType, immutableType.getName());
} else {
typeContributions.contributeType(type, type.getClass().getSimpleName());
}
typeContributions.contributeType(type, type.getClass().getSimpleName());
return this;
}
}
Expand Up @@ -8,10 +8,10 @@
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.type.BasicType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.IncomparableComparator;
import org.hibernate.type.spi.TypeBootstrapContext;
import org.hibernate.usertype.UserType;

import java.io.Serializable;
Expand All @@ -29,7 +29,7 @@
*
* @author Vlad Mihalcea
*/
public abstract class ImmutableType<T> implements UserType, Type {
public abstract class ImmutableType<T> implements UserType, BasicType {

private final Configuration configuration;

Expand Down Expand Up @@ -320,4 +320,9 @@ public Object replace(Object original, Object target, SharedSessionContractImple
public boolean[] toColumnNullness(Object value, Mapping mapping) {
return value == null ? ArrayHelper.FALSE : ArrayHelper.TRUE;
}

@Override
public String[] getRegistrationKeys() {
return new String[]{getName()};
}
}
Expand Up @@ -5,6 +5,7 @@
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.envers.Audited;
import org.junit.Test;

import javax.persistence.*;
Expand Down Expand Up @@ -67,6 +68,7 @@ public void test() {
});
}

@Audited
@Entity(name = "Book")
@Table(name = "book")
@TypeDef(name = "hstore", typeClass = PostgreSQLHStoreType.class)
Expand Down

0 comments on commit c8876e8

Please sign in to comment.