|
| 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