title: How to validate constraints of ManyToOne relations?
body: <p>I've got two models with <code>1:n</code> relation and want to use form validators.</p>
  
  <p>If I choose an option from the select, the correct id of the element is stored on the database.<br>
  But if I leave it <code>-- Choose a game--</code>, <em><code>NULL</code></em> is stored although the game property is annotated with <code>@Constraints.Required</code>.</p>
  
  <h2>Models</h2>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class Server extends Model {
  
      @Id
      public Integer serverId;
  
      @ManyToOne
      @Constraints.Required
      public Game game;
  
      ...
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class Game extends Model {
  
      @Id
      @Constraints.Required
      public Integer gameId;
  
      @Constraints.Required
      public String name;
  
      public static Map&lt;String,String&gt; options() {
          LinkedHashMap&lt;String,String&gt; options = new LinkedHashMap&lt;String,String&gt;();
  
          for(Game c: Game.find.orderBy("name").findList()) {
              options.put(c.gameId.toString(), c.name);
          }
  
          return options;
      }
  
      ...
  }
  </code></pre>
  
  <h2>Controller</h2>
  
  <pre class="lang-java prettyprint-override"><code>public static Result create() {
      return ok(views.html.Server.create.render(form(models.Server.class)))
  }
  </code></pre>
  
  <h2>Template</h2>
  
  <pre class="lang-scala prettyprint-override"><code>@helper.select(form("game.gameId"), helper.options(Game.options), '_default -&gt; "-- Choose a game --")
  </code></pre>
  
  <hr>
  
  <p>I've already tried to use a <code>@Valid</code> annotation to force <code>play.data.Form</code> to validate the <code>Game</code>-Model during the binding process, but that only causes a simple evaluation of the constraints on <code>Game</code> properties, which are not filled. Although a correct game is choosen from the list, it gives me an error that <code>name</code> is empty:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class Server extends Model {
  
      @ManyToOne
      @Constraints.Required
      @Valid
      public Game game;
  
      @Constraints.Required
      public String name;
  
  ...
  </code></pre>
  
  <hr>
  
  <p>Thanks for your help.</p>