Example usage for org.hibernate.type Type getSemiResolvedType

List of usage examples for org.hibernate.type Type getSemiResolvedType

Introduction

In this page you can find the example usage for org.hibernate.type Type getSemiResolvedType.

Prototype

Type getSemiResolvedType(SessionFactoryImplementor factory);

Source Link

Document

As part of 2-phase loading, when we perform resolving what is the resolved type for this type?

Usage

From source file:com.hazelcast.hibernate.region.NaturalIdCacheKey.java

License:Open Source License

@SuppressWarnings("checkstyle:magicnumber")
public NaturalIdCacheKey(final Object[] naturalIdValues, Type[] propertyTypes, int[] naturalIdPropertyIndexes,
        final String entityName, final SharedSessionContractImplementor session) {

    this.naturalIdValues = new Serializable[naturalIdValues.length];
    this.entityName = entityName;
    this.tenantId = session.getTenantIdentifier();

    SessionFactoryImplementor factory = session.getFactory();

    int result = 1;
    result = 31 * result + (entityName != null ? entityName.hashCode() : 0);
    result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0);

    for (int i = 0; i < naturalIdValues.length; i++) {
        final int naturalIdPropertyIndex = naturalIdPropertyIndexes[i];
        final Type type = propertyTypes[naturalIdPropertyIndex];
        final Object value = naturalIdValues[i];

        result = 31 * result + (value != null ? type.getHashCode(value, factory) : 0);

        if (type instanceof EntityType
                && type.getSemiResolvedType(factory).getReturnedClass().isInstance(value)) {
            this.naturalIdValues[i] = (Serializable) value;
        } else {/*  ww  w  .  j ava  2s . c o  m*/
            this.naturalIdValues[i] = type.disassemble(value, session, null);
        }
    }
    this.hashCode = result;
}