|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.orm.test.annotations.basic; |
| 6 | + |
| 7 | +import jakarta.persistence.Basic; |
| 8 | +import jakarta.persistence.Entity; |
| 9 | +import jakarta.persistence.GeneratedValue; |
| 10 | +import jakarta.persistence.Id; |
| 11 | +import org.hibernate.boot.Metadata; |
| 12 | +import org.hibernate.boot.MetadataSources; |
| 13 | +import org.hibernate.mapping.PersistentClass; |
| 14 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 15 | +import org.hibernate.testing.orm.junit.NotImplementedYet; |
| 16 | +import org.hibernate.testing.orm.junit.ServiceRegistry; |
| 17 | +import org.hibernate.testing.orm.junit.ServiceRegistryScope; |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 21 | + |
| 22 | +/** |
| 23 | + * <pre> |
| 24 | + * Javadoc to @{@link Basic} : |
| 25 | + * The use of the Basic annotation is optional for persistent fields and properties of these types. |
| 26 | + * If the Basic annotation is not specified for such a field or property, the default values of the Basic annotation apply. |
| 27 | + * |
| 28 | + * And the property : |
| 29 | + * |
| 30 | + * <code>boolean optional() default true;</code> |
| 31 | + * |
| 32 | + * But if we add the @Basic annotation or not on a boolean type, we do not get the same result. |
| 33 | + * In one case, the boolean is optional, while in the other, it is not, which contradicts the Javadoc. |
| 34 | + * </pre> |
| 35 | + * |
| 36 | + * @author Vincent Bouthinon |
| 37 | + */ |
| 38 | +@ServiceRegistry() |
| 39 | +@JiraKey("HHH-19279") |
| 40 | +class ImpliciteOptionalBooleanBasicTest { |
| 41 | + |
| 42 | + @NotImplementedYet |
| 43 | + @Test |
| 44 | + void testImpliciteOptionalBooleanBasic(ServiceRegistryScope registryScope) { |
| 45 | + final MetadataSources metadataSources = new MetadataSources( registryScope.getRegistry() ) |
| 46 | + .addAnnotatedClasses( BooleanBasicTest.class ); |
| 47 | + Metadata metadata = metadataSources.buildMetadata(); |
| 48 | + PersistentClass entityBinding = metadata.getEntityBinding( BooleanBasicTest.class.getName() ); |
| 49 | + assertTrue( entityBinding.getProperty( "booleanWithBasic" ).isOptional(), "booleanWithBasic property is not optional" ); |
| 50 | + assertTrue( entityBinding.getProperty( "booleanWithoutBasic" ).isOptional(), "booleanWithoutBasic property is not optional" ); |
| 51 | + } |
| 52 | + |
| 53 | + @Entity |
| 54 | + public static class BooleanBasicTest { |
| 55 | + |
| 56 | + @Id |
| 57 | + @GeneratedValue |
| 58 | + private Long id; |
| 59 | + |
| 60 | + @Basic |
| 61 | + private boolean booleanWithBasic; |
| 62 | + |
| 63 | + private boolean booleanWithoutBasic; |
| 64 | + } |
| 65 | +} |
0 commit comments