public String getNotNullAnnotation ( ) { if ( ! relation . isManyToOne ( ) && ! relation . isOneToOne ( ) ) { return "" ; } if ( relation . isMandatory ( ) && ! relation . hasInverse ( ) ) { if ( relation . getFromEntity ( ) . getName ( ) . equals ( relation . getToEntity ( ) . getName ( ) ) ) { // TODO ?: mandatory relation on self is complicated to handled // in tests (model generator)... so we just ignore it. return "" ; } if ( relation . getFromAttribute ( ) . isInPk ( ) ) { // TODO: not sure why, but integration tests fail if we don't skip this case. return "" ; } ImportsContext . addImport ( "javax.validation.constraints.NotNull" ) ; return "@NotNull" ; } else { return "" ; } }
Applies only to ManyToOne or OneToOne . When x to one has an inverse relation we never mark it as