Skip to content
Browse files

ROO-3279: Hibernate startup fails when JoinColumns has multiple JoinC…

…olumn with distinct nullable attribute values
  • Loading branch information...
1 parent d597b4e commit f54d05d9bd0f64697b5c31f54996434943bf2a5e Alan Stewart committed
Showing with 25 additions and 3 deletions.
  1. +25 −3 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreMetadata.java
View
28 addon-dbre/src/main/java/org/springframework/roo/addon/dbre/DbreMetadata.java
@@ -781,6 +781,13 @@ private AnnotationMetadataBuilder getJoinColumnAnnotation(
private AnnotationMetadataBuilder getJoinColumnAnnotation(
final Reference reference, final boolean referencedColumn,
final JavaType fieldType) {
+ return getJoinColumnAnnotation(reference, referencedColumn, fieldType,
+ null);
+ }
+
+ private AnnotationMetadataBuilder getJoinColumnAnnotation(
+ final Reference reference, final boolean referencedColumn,
+ final JavaType fieldType, final Boolean nullable) {
final Column localColumn = reference.getLocalColumn();
Validate.notNull(localColumn, "Foreign-key reference local column '"
+ reference.getLocalColumnName() + "' must not be null");
@@ -800,8 +807,13 @@ private AnnotationMetadataBuilder getJoinColumnAnnotation(
foreignColumn.getEscapedName());
}
- if (localColumn.isRequired()) {
- joinColumnBuilder.addBooleanAttribute("nullable", false);
+ if (nullable == null) {
+ if (localColumn.isRequired()) {
+ joinColumnBuilder.addBooleanAttribute("nullable", false);
+ }
+ }
+ else {
+ joinColumnBuilder.addBooleanAttribute("nullable", nullable);
}
if (fieldType != null) {
@@ -818,9 +830,19 @@ private AnnotationMetadataBuilder getJoinColumnAnnotation(
private AnnotationMetadataBuilder getJoinColumnsAnnotation(
final Set<Reference> references, final JavaType fieldType) {
final List<NestedAnnotationAttributeValue> arrayValues = new ArrayList<NestedAnnotationAttributeValue>();
+
+ // XXX DiSiD: Nullable attribute will have same value for each
+ // If some column not required, all JoinColumn will be nullable
+ boolean nullable = false;
+ for (final Reference reference : references) {
+ if (!reference.getLocalColumn().isRequired()) {
+ nullable = true;
+ }
+ }
+
for (final Reference reference : references) {
final AnnotationMetadataBuilder joinColumnAnnotation = getJoinColumnAnnotation(
- reference, true, fieldType);
+ reference, true, fieldType, nullable);
arrayValues.add(new NestedAnnotationAttributeValue(
new JavaSymbolName(VALUE), joinColumnAnnotation.build()));
}

0 comments on commit f54d05d

Please sign in to comment.
Something went wrong with that request. Please try again.