From 7488bda45558911d274f5dd4b42f1324309d0349 Mon Sep 17 00:00:00 2001 From: Vineet Reynolds Date: Wed, 12 Mar 2014 23:12:39 +0530 Subject: [PATCH] Add required field only for OneToOne and ManyToOne field types. This ensures that the 'required' is not present for OneToMany and ManyToMany fields, since they do not have any optional semantics. --- .../javaee/jpa/ui/NewFieldRelationshipWizardStep.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/javaee/impl/src/main/java/org/jboss/forge/addon/javaee/jpa/ui/NewFieldRelationshipWizardStep.java b/javaee/impl/src/main/java/org/jboss/forge/addon/javaee/jpa/ui/NewFieldRelationshipWizardStep.java index e9dd4ed138..9b890892c8 100644 --- a/javaee/impl/src/main/java/org/jboss/forge/addon/javaee/jpa/ui/NewFieldRelationshipWizardStep.java +++ b/javaee/impl/src/main/java/org/jboss/forge/addon/javaee/jpa/ui/NewFieldRelationshipWizardStep.java @@ -62,6 +62,7 @@ public void initializeUI(UIBuilder builder) throws Exception Map attributeMap = context.getAttributeMap(); RelationshipType relationship = RelationshipType.valueOf(attributeMap.get(RelationshipType.class).toString()); cascadeType.setValueChoices(EnumSet.range(CascadeType.PERSIST, CascadeType.DETACH)); + boolean shouldAddRequired = false; switch (relationship) { case MANY_TO_MANY: @@ -71,11 +72,17 @@ public void initializeUI(UIBuilder builder) throws Exception case MANY_TO_ONE: case ONE_TO_ONE: fetchType.setDefaultValue(FetchType.EAGER); + shouldAddRequired = true; break; default: throw new UnsupportedOperationException("Relationship " + relationship + " is not supported"); } - builder.add(fetchType).add(inverseFieldName).add(required).add(cascadeType); + builder.add(fetchType).add(inverseFieldName); + if (shouldAddRequired) + { + builder.add(required); + } + builder.add(cascadeType); } @Override