Skip to content

Commit

Permalink
Add required field only for OneToOne and ManyToOne field types.
Browse files Browse the repository at this point in the history
This ensures that the 'required' is not present for OneToMany
and ManyToMany fields, since they do not have any optional
semantics.
  • Loading branch information
VineetReynolds committed Mar 12, 2014
1 parent 88718b4 commit 7488bda
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void initializeUI(UIBuilder builder) throws Exception
Map<Object, Object> 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:
Expand All @@ -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
Expand Down

0 comments on commit 7488bda

Please sign in to comment.