Skip to content

Commit d57676a

Browse files
Armin Krezovićmbellade
authored andcommitted
HHH-16253 - Schema Validation Failure With Audited (N)Clob Column
https://hibernate.atlassian.net/browse/HHH-16253 Signed-off-by: Armin Krezović <armin.krezovic@ziragroup.com>
1 parent a947d56 commit d57676a

File tree

2 files changed

+97
-5
lines changed

2 files changed

+97
-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
@@ -155,6 +155,7 @@
155155
import org.hibernate.type.CustomType;
156156
import org.hibernate.type.ForeignKeyDirection;
157157
import org.hibernate.type.StandardBasicTypes;
158+
import org.hibernate.type.internal.BasicTypeImpl;
158159
import org.hibernate.type.spi.TypeConfiguration;
159160
import org.hibernate.usertype.CompositeUserType;
160161
import org.hibernate.usertype.ParameterizedType;
@@ -1877,11 +1878,14 @@ private void resolveLob(final SingularAttributeSourceBasic attributeSource, Simp
18771878
// Resolves whether the property is LOB based on the type attribute on the attribute property source.
18781879
// Essentially this expects the type to map to a CLOB/NCLOB/BLOB sql type internally and compares.
18791880
if ( !value.isLob() && value.getTypeName() != null ) {
1880-
final BasicType<?> basicType = attributeSource.getBuildingContext()
1881-
.getMetadataCollector()
1882-
.getTypeConfiguration()
1883-
.getBasicTypeRegistry()
1884-
.getRegisteredType( value.getTypeName() );
1881+
final String typeName = value.getTypeName();
1882+
final MetadataBuildingContext context = attributeSource.getBuildingContext();
1883+
final BasicType<?> basicType =
1884+
typeName.startsWith( BasicTypeImpl.EXTERNALIZED_PREFIX )
1885+
? context.getBootstrapContext().resolveAdHocBasicType( typeName )
1886+
: context.getMetadataCollector().getTypeConfiguration()
1887+
.getBasicTypeRegistry().getRegisteredType( typeName );
1888+
18851889
if ( basicType instanceof AbstractSingleColumnStandardBasicType ) {
18861890
if ( isLob( basicType.getJdbcType().getDdlTypeCode(), null ) ) {
18871891
value.makeLob();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 boolean equals(Object o) {
56+
if ( o == null || getClass() != o.getClass() ) {
57+
return false;
58+
}
59+
60+
final LargeObjectTestEntity that = (LargeObjectTestEntity) o;
61+
return Objects.equals( id, that.id ) && Objects.equals(
62+
clob,
63+
that.clob
64+
) && Arrays.equals( blob, that.blob );
65+
}
66+
67+
@Override
68+
public int hashCode() {
69+
return Objects.hash( id, clob, Arrays.hashCode( blob ) );
70+
}
71+
}
72+
73+
@Override
74+
protected Class<?>[] getAnnotatedClasses() {
75+
return new Class<?>[] { LargeObjectTestEntity.class };
76+
}
77+
78+
@Test
79+
public void testLobTypeMapping() {
80+
PersistentClass entityBinding = metadata().getEntityBinding( LargeObjectTestEntity.class.getName() + "_AUD" );
81+
82+
Property blobProperty = entityBinding.getProperty( "blob" );
83+
Property clobProperty = entityBinding.getProperty( "clob" );
84+
85+
assertTrue( blobProperty.isLob() );
86+
assertTrue( clobProperty.isLob() );
87+
}
88+
}

0 commit comments

Comments
 (0)