| 
 | 1 | +/*  | 
 | 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later  | 
 | 3 | + * Copyright Red Hat Inc. and Hibernate Authors  | 
 | 4 | + */  | 
 | 5 | +package org.hibernate.orm.test.type;  | 
 | 6 | + | 
 | 7 | +import jakarta.persistence.Column;  | 
 | 8 | +import jakarta.persistence.Entity;  | 
 | 9 | +import jakarta.persistence.GeneratedValue;  | 
 | 10 | +import jakarta.persistence.Id;  | 
 | 11 | +import org.hibernate.annotations.JdbcTypeCode;  | 
 | 12 | +import org.hibernate.testing.orm.junit.DomainModel;  | 
 | 13 | +import org.hibernate.testing.orm.junit.SessionFactory;  | 
 | 14 | +import org.hibernate.testing.orm.junit.SessionFactoryScope;  | 
 | 15 | +import org.hibernate.type.SqlTypes;  | 
 | 16 | +import org.junit.jupiter.api.Test;  | 
 | 17 | + | 
 | 18 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals;  | 
 | 19 | +import static org.junit.jupiter.api.Assertions.assertEquals;  | 
 | 20 | + | 
 | 21 | +@DomainModel(annotatedClasses = LongNullTest.Foo.class)  | 
 | 22 | +@SessionFactory  | 
 | 23 | +public class LongNullTest {  | 
 | 24 | + | 
 | 25 | +	@Entity  | 
 | 26 | +	public static final class Foo {  | 
 | 27 | +		@Id  | 
 | 28 | +		@GeneratedValue  | 
 | 29 | +		private Long id;  | 
 | 30 | + | 
 | 31 | +		@JdbcTypeCode(SqlTypes.LONG32NVARCHAR)  | 
 | 32 | +		@Column  | 
 | 33 | +		private String field = null;  | 
 | 34 | + | 
 | 35 | +		@JdbcTypeCode(SqlTypes.LONG32VARCHAR)  | 
 | 36 | +		@Column  | 
 | 37 | +		private String nfield = null;  | 
 | 38 | + | 
 | 39 | +		@JdbcTypeCode(SqlTypes.LONG32VARBINARY)  | 
 | 40 | +		@Column  | 
 | 41 | +		private byte[] bfield = null;  | 
 | 42 | +	}  | 
 | 43 | + | 
 | 44 | +	@Test  | 
 | 45 | +	public void testNull(SessionFactoryScope scope) {  | 
 | 46 | +		final var expected = scope.fromTransaction( s -> {  | 
 | 47 | +			final var foo = new Foo();  | 
 | 48 | +			s.persist( foo );  | 
 | 49 | +			return foo;  | 
 | 50 | +		} );  | 
 | 51 | +		final var actual = scope.fromSession( s -> s.find( Foo.class, expected.id ) );  | 
 | 52 | +		assertEquals( expected.field, actual.field );  | 
 | 53 | +		assertEquals( expected.nfield, actual.nfield );  | 
 | 54 | +		assertArrayEquals( expected.bfield, actual.bfield );  | 
 | 55 | +	}  | 
 | 56 | + | 
 | 57 | +	@Test  | 
 | 58 | +	public void testNonNull(SessionFactoryScope scope) {  | 
 | 59 | +		final var expected = scope.fromTransaction( s -> {  | 
 | 60 | +			final var foo = new Foo();  | 
 | 61 | +			foo.bfield = "ABC".getBytes();  | 
 | 62 | +			foo.field = "DEF";  | 
 | 63 | +			foo.nfield = "GHI";  | 
 | 64 | +			s.persist( foo );  | 
 | 65 | +			return foo;  | 
 | 66 | +		} );  | 
 | 67 | +		final var actual = scope.fromSession( s -> s.find( Foo.class, expected.id ) );  | 
 | 68 | +		assertEquals( expected.field, actual.field );  | 
 | 69 | +		assertEquals( expected.nfield, actual.nfield );  | 
 | 70 | +		assertArrayEquals( expected.bfield, actual.bfield );  | 
 | 71 | +	}  | 
 | 72 | +}  | 
0 commit comments