|
24 | 24 | package org.hibernate.cfg.beanvalidation.ddl;
|
25 | 25 |
|
26 | 26 | import java.util.Iterator;
|
| 27 | + |
27 | 28 | import javax.validation.constraints.NotNull;
|
28 | 29 | import javax.validation.metadata.ConstraintDescriptor;
|
29 | 30 | import javax.validation.metadata.PropertyDescriptor;
|
|
33 | 34 | import org.hibernate.mapping.Property;
|
34 | 35 | import org.hibernate.mapping.SingleTableSubclass;
|
35 | 36 | import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
| 37 | +import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; |
36 | 38 | import org.hibernate.metamodel.spi.binding.EntityBinding;
|
37 | 39 | import org.hibernate.metamodel.spi.binding.InheritanceType;
|
38 | 40 |
|
@@ -74,15 +76,34 @@ public boolean applyConstraint(AttributeBinding attributeBinding, ConstraintDesc
|
74 | 76 | if(InheritanceType.SINGLE_TABLE.equals( inheritanceType )) {
|
75 | 77 | return false;
|
76 | 78 | }
|
77 |
| - |
78 |
| - org.hibernate.metamodel.spi.relational.Column column = SchemaModificationHelper.getSingleColumn( attributeBinding ); |
79 |
| - if ( column == null ) { |
80 |
| - return false; |
| 79 | + |
| 80 | + // If a Composite (Embeddable static type, etc.), use the attribute's |
| 81 | + // nullability on the static type's fields. |
| 82 | + |
| 83 | + // TODO: Is this the correct place to do this? Higher up in |
| 84 | + // TypeSafeActivator? |
| 85 | + if ( attributeBinding instanceof CompositeAttributeBinding ) { |
| 86 | + Iterator<AttributeBinding> iter |
| 87 | + = ( ( CompositeAttributeBinding ) attributeBinding) |
| 88 | + .attributeBindings().iterator(); |
| 89 | + while( iter.hasNext() ) { |
| 90 | + applyNullConstraint( iter.next() ); |
| 91 | + } |
| 92 | + } else { |
| 93 | + applyNullConstraint( attributeBinding ); |
81 | 94 | }
|
82 | 95 |
|
83 |
| - // TODO check with components as in the old configuration approach. see above (HF) |
84 |
| - column.setNullable( false ); |
| 96 | + |
85 | 97 |
|
86 | 98 | return true;
|
87 | 99 | }
|
| 100 | + |
| 101 | + private void applyNullConstraint(AttributeBinding attributeBinding) { |
| 102 | + org.hibernate.metamodel.spi.relational.Column column |
| 103 | + = SchemaModificationHelper.getSingleColumn( attributeBinding ); |
| 104 | + if ( column != null ) { |
| 105 | + // TODO check with components as in the old configuration approach. see above (HF) |
| 106 | + column.setNullable( false ); |
| 107 | + } |
| 108 | + } |
88 | 109 | }
|
0 commit comments