Skip to content

[6.6] HHH-16253 - Schema Validation Failure With Audited (N)Clob Column #10608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
import org.hibernate.type.CustomType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.internal.BasicTypeImpl;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.ParameterizedType;
Expand Down Expand Up @@ -1877,11 +1878,14 @@ private void resolveLob(final SingularAttributeSourceBasic attributeSource, Simp
// Resolves whether the property is LOB based on the type attribute on the attribute property source.
// Essentially this expects the type to map to a CLOB/NCLOB/BLOB sql type internally and compares.
if ( !value.isLob() && value.getTypeName() != null ) {
final BasicType<?> basicType = attributeSource.getBuildingContext()
.getMetadataCollector()
.getTypeConfiguration()
.getBasicTypeRegistry()
.getRegisteredType( value.getTypeName() );
final String typeName = value.getTypeName();
final MetadataBuildingContext context = attributeSource.getBuildingContext();
final BasicType<?> basicType =
typeName.startsWith( BasicTypeImpl.EXTERNALIZED_PREFIX )
? context.getBootstrapContext().resolveAdHocBasicType( typeName )
: context.getMetadataCollector().getTypeConfiguration()
.getBasicTypeRegistry().getRegisteredType( typeName );

if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
if ( isLob( basicType.getJdbcType().getDdlTypeCode(), null ) ) {
value.makeLob();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.envers.integration.lob;

import java.sql.Types;
import java.util.Arrays;
import java.util.Objects;

import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.envers.Audited;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;

import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

import static org.junit.Assert.assertTrue;

/**
* @author Armin Krezović (armin.krezovic at ziragroup dot com)
*/
@JiraKey(value = "HHH-16253")
public class LargeObjectMappingTest extends BaseEnversJPAFunctionalTestCase {

@Entity
@Audited
public static class LargeObjectTestEntity {
@Id
@GeneratedValue
private Integer id;

@JdbcTypeCode(Types.CLOB)
private String clob;

@JdbcTypeCode(Types.BLOB)
private byte[] blob;

public LargeObjectTestEntity() {
}

public LargeObjectTestEntity(Integer id, String clob, byte[] blob) {
this.id = id;
this.clob = clob;
this.blob = blob;
}

@Override
public boolean equals(Object o) {
if ( o == null || getClass() != o.getClass() ) {
return false;
}

final LargeObjectTestEntity that = (LargeObjectTestEntity) o;
return Objects.equals( id, that.id ) && Objects.equals(
clob,
that.clob
) && Arrays.equals( blob, that.blob );
}

@Override
public int hashCode() {
return Objects.hash( id, clob, Arrays.hashCode( blob ) );
}
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { LargeObjectTestEntity.class };
}

@Test
public void testLobTypeMapping() {
PersistentClass entityBinding = metadata().getEntityBinding( LargeObjectTestEntity.class.getName() + "_AUD" );

Property blobProperty = entityBinding.getProperty( "blob" );
Property clobProperty = entityBinding.getProperty( "clob" );

assertTrue( blobProperty.isLob() );
assertTrue( clobProperty.isLob() );
}
}
Loading