Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1264,26 +1264,25 @@ private boolean shouldForceNotNull(Nullability nullability, boolean optional) {
* Should this property be considered optional, without considering
* whether it is primitive?
*
* @apiNote Poorly named to a degree. The intention is really whether non-optional is explicit
* @apiNote Poorly named to a degree.
* The intention is really whether non-optional is explicit
*/
private static boolean isExplicitlyOptional(MemberDetails attributeMember) {
final Basic basicAnn = attributeMember.getDirectAnnotationUsage( Basic.class );
if ( basicAnn == null ) {
// things are optional (nullable) by default. If there is no annotation, that cannot be altered
return true;
}

return basicAnn.optional();
final Basic basic = attributeMember.getDirectAnnotationUsage( Basic.class );
// things are optional (nullable) by default.
// If there is no annotation, that cannot be altered
return basic == null || basic.optional();
}

/**
* Should this property be considered optional, taking into
* account whether it is primitive?
* Should this property be considered optional, taking into account
* whether it is primitive?
*/
public static boolean isOptional(MemberDetails attributeMember, PropertyHolder propertyHolder) {
final Basic basicAnn = attributeMember.getDirectAnnotationUsage( Basic.class );
if ( basicAnn != null ) {
return basicAnn.optional();
final Basic basic = attributeMember.getDirectAnnotationUsage( Basic.class );
if ( basic != null ) {
return basic.optional()
&& attributeMember.getType().getTypeKind() != TypeDetails.Kind.PRIMITIVE;
}
else if ( attributeMember.isArray() ) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
import org.hibernate.boot.MetadataSources;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

/**
* <pre>
Expand All @@ -37,17 +36,16 @@
*/
@ServiceRegistry()
@JiraKey("HHH-19279")
class ImpliciteOptionalBooleanBasicTest {
class ImplicitOptionalBooleanBasicTest {

@NotImplementedYet
@Test
void testImpliciteOptionalBooleanBasic(ServiceRegistryScope registryScope) {
void testImplicitOptionalBooleanBasic(ServiceRegistryScope registryScope) {
final MetadataSources metadataSources = new MetadataSources( registryScope.getRegistry() )
.addAnnotatedClasses( BooleanBasicTest.class );
Metadata metadata = metadataSources.buildMetadata();
PersistentClass entityBinding = metadata.getEntityBinding( BooleanBasicTest.class.getName() );
assertTrue( entityBinding.getProperty( "booleanWithBasic" ).isOptional(), "booleanWithBasic property is not optional" );
assertTrue( entityBinding.getProperty( "booleanWithoutBasic" ).isOptional(), "booleanWithoutBasic property is not optional" );
assertFalse( entityBinding.getProperty( "booleanWithBasic" ).isOptional(), "primitive property is optional" );
assertFalse( entityBinding.getProperty( "booleanWithoutBasic" ).isOptional(), "primitive property is optional" );
}

@Entity
Expand Down
Loading