Skip to content

Commit 317b8c6

Browse files
author
Armin Krezović
committed
HHH-16253 - Schema Validation Failure With Audited (N)Clob Column
https://hibernate.atlassian.net/browse/HHH-16253 Signed-off-by: Armin Krezović <[email protected]>
1 parent 97a0c68 commit 317b8c6

File tree

2 files changed

+100
-5
lines changed

2 files changed

+100
-5
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
import org.hibernate.type.CustomType;
102102
import org.hibernate.type.ForeignKeyDirection;
103103
import org.hibernate.type.StandardBasicTypes;
104+
import org.hibernate.type.internal.BasicTypeImpl;
104105
import org.hibernate.type.spi.TypeConfiguration;
105106
import org.hibernate.usertype.CompositeUserType;
106107
import org.hibernate.usertype.ParameterizedType;
@@ -1726,11 +1727,14 @@ private void resolveLob(final SingularAttributeSourceBasic attributeSource, Simp
17261727
// Resolves whether the property is LOB based on the type attribute on the attribute property source.
17271728
// Essentially this expects the type to map to a CLOB/NCLOB/BLOB sql type internally and compares.
17281729
if ( !value.isLob() && value.getTypeName() != null ) {
1729-
final BasicType<?> basicType = attributeSource.getBuildingContext()
1730-
.getMetadataCollector()
1731-
.getTypeConfiguration()
1732-
.getBasicTypeRegistry()
1733-
.getRegisteredType( value.getTypeName() );
1730+
final String typeName = value.getTypeName();
1731+
final MetadataBuildingContext context = attributeSource.getBuildingContext();
1732+
final BasicType<?> basicType =
1733+
typeName.startsWith( BasicTypeImpl.EXTERNALIZED_PREFIX )
1734+
? context.getBootstrapContext().resolveAdHocBasicType( typeName )
1735+
: context.getMetadataCollector().getTypeConfiguration()
1736+
.getBasicTypeRegistry().getRegisteredType( typeName );
1737+
17341738
if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
17351739
if ( isLob( basicType.getJdbcType().getDdlTypeCode(), null ) ) {
17361740
value.makeLob();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.envers.integration.lob;
6+
7+
import java.sql.Types;
8+
import java.util.Arrays;
9+
import java.util.Objects;
10+
11+
import org.hibernate.annotations.JdbcTypeCode;
12+
import org.hibernate.envers.Audited;
13+
import org.hibernate.mapping.PersistentClass;
14+
import org.hibernate.mapping.Property;
15+
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
16+
17+
import org.hibernate.testing.orm.junit.JiraKey;
18+
import org.junit.Test;
19+
20+
import jakarta.persistence.Entity;
21+
import jakarta.persistence.GeneratedValue;
22+
import jakarta.persistence.Id;
23+
24+
import static org.junit.Assert.assertTrue;
25+
26+
/**
27+
* @author Armin Krezović (armin.krezovic at ziragroup dot com)
28+
*/
29+
@JiraKey(value = "HHH-16253")
30+
public class LargeObjectMappingTest extends BaseEnversJPAFunctionalTestCase {
31+
32+
@Entity
33+
@Audited
34+
public static class LargeObjectTestEntity {
35+
@Id
36+
@GeneratedValue
37+
private Integer id;
38+
39+
@JdbcTypeCode(Types.CLOB)
40+
private String clob;
41+
42+
@JdbcTypeCode(Types.BLOB)
43+
private byte[] blob;
44+
45+
public LargeObjectTestEntity() {
46+
}
47+
48+
public LargeObjectTestEntity(Integer id, String clob, byte[] blob) {
49+
this.id = id;
50+
this.clob = clob;
51+
this.blob = blob;
52+
}
53+
54+
@Override
55+
public final boolean equals(Object o) {
56+
if ( this == o ) {
57+
return true;
58+
}
59+
60+
if ( !( o instanceof LargeObjectTestEntity that ) ) {
61+
return false;
62+
}
63+
64+
return Objects.equals( id, that.id ) && Objects.equals(
65+
clob,
66+
that.clob
67+
) && Arrays.equals( blob, that.blob );
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
return Objects.hash( id, clob, Arrays.hashCode( blob ) );
73+
}
74+
}
75+
76+
@Override
77+
protected Class<?>[] getAnnotatedClasses() {
78+
return new Class<?>[] { LargeObjectTestEntity.class };
79+
}
80+
81+
@Test
82+
public void testLobTypeMapping() {
83+
PersistentClass entityBinding = metadata().getEntityBinding( LargeObjectTestEntity.class.getName() + "_AUD" );
84+
85+
Property blobProperty = entityBinding.getProperty( "blob" );
86+
Property clobProperty = entityBinding.getProperty( "clob" );
87+
88+
assertTrue( blobProperty.isLob() );
89+
assertTrue( clobProperty.isLob() );
90+
}
91+
}

0 commit comments

Comments
 (0)