Creating a custom VersionType

Hi all! I need advice, because I didn’t find a way to do it.

We want to implement a custom VersionType in which we are trying to override the Versiontype.next() method. Since we want to bind the version calculation logic to the hashcode of the entity object. There was a question. How can you access the computed object inside the VersionType?

public class HyperVersionType extends AbstractSingleColumnStandardBasicType<Short>
        implements PrimitiveType<Short>, DiscriminatorType<Short>, VersionType<Short>
    @Override
    public Short next(Short current, SharedSessionContractImplementor session) {
        return (short) (current + 1);
    }
    @NotNull
    @Version
    @Type(type = "org.hyperobjects.objcore.model.obj.HyperVersionType")
    @Column(name = "version", nullable = false)
    private short version;

Thanks in advance!

computed object

You mean the entity? There is no way to access the entity from these contracts. If you need something like that, I’d recommend you to use a @PrePersist and @PreUpdate listener for doing that.