title: Why does my Play framework model save to the database as a blank record?
body: <p>I am fairly new to Java and working on a web-based project using the Play framework. It's been a great learning experience and I've been able to find solutions to most of problems, but I'm stuck on saving a model to the database.</p>
  
  <p>I am using framework version 2.3.4 with a postgresql database running locally. The connection is fine, but when I use the .save() method on my object(Newspaper) a blank record is saved with only the ID field having any data. The form seems to have the values binded by the request just fine. Why can't this be saved?</p>
  
  <p>I've searched for answers, but it doesn't seem like anyone has had this issue.</p>
  
  <p>I have noticed that the ID generated by the sequence doesn't always use the next number (skips 20 or so) even though I'm running locally and the only user?? That may be a clue for someone...</p>
  
  <p>Here's the model:</p>
  
  <pre><code>package models;
  
  import java.util.*;
  import javax.persistence.*;
  
  import play.mvc.*;
  
  import play.db.ebean.Model;
  import play.data.validation.*;
  
  /**
   * Newspaper entity managed by Ebean
   */
  @Entity
  public class Newspaper extends Model {
  
  private static final long serialVersionUID = -4004723260163933009L;
  
  @Id
  @GeneratedValue(generator="newspaper_seq")
  @SequenceGenerator(name="newspaper_seq", allocationSize=1)
  public Long id;
  
  public String name;
  
  public Long rate;
  
  /**
   * Generic query helper for entity Newspaper with id Long
   */
  public static Model.Finder&lt;Long,Newspaper&gt; find = new Model.Finder&lt;Long,Newspaper&gt;(Long.class, Newspaper.class);
  
  public static Map&lt;String,String&gt; options() {
      LinkedHashMap&lt;String,String&gt; options = new LinkedHashMap&lt;String,String&gt;();
      for(Newspaper c: Newspaper.find.orderBy("name").findList()) {
          options.put(c.id.toString(), c.name);
      }
      return options;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And my controller class:</p>
  
  <pre><code>package controllers;
  
  
  import play.*;
  
  import play.mvc.*;
  
  
  import views.html.*;
  
  import models.Newspaper;
  
  //import play.api.data.Form; 
  
  import play.data.Form;
  
  public class Application extends Controller{
  
  /**
   * @param args
   */
  public static Result index() {
      return ok(views.html.index.render("list of newspapers"));
  
  }
  
  public static Result addNewspaper() {
      Form&lt;Newspaper&gt; form = Form.form(Newspaper.class).bindFromRequest();
      //return ok(form.toString()); 
      if(form.hasErrors()) {
          return badRequest("something didn't work");
      }
      String oldForm = form.toString();
      Newspaper paper = form.get();
      paper.save();
  
  
  // checking value        return ok(oldForm + "\n" + form.toString() + "\n" + paper.toString());
    return redirect(routes.Application
            .index()); 
  }
  
  
  }
  </code></pre>
  
  <p>And here is my SQL to create the table (first time using postgresql so this could be wrong)</p>
  
  <pre><code>create table newspaper (
  id                        bigint not null,
  name                      varchar(255),
  rate                      bigint,
  constraint pk_newspaper primary key (id))
  ;
  
  create sequence newspaper_seq;
  </code></pre>
  
  <p>Thank you for your time!</p>
  
  <p><strong>---Update---</strong>
  I started sql debugging and I saw this error in the terminal :</p>
  
  <pre><code>[debug] c.j.b.PreparedStatementHandle - insert into newspaper (id, name, rate) values (101,'[SQL NULL of type 12]','[SQL NULL of type -5]')
  </code></pre>
  
  <p>For some reason, the values are NULL (of different types?), but when I output the <code>.toString</code> value of the form it seems to show the correct data:</p>
  
  <pre><code>Form(of=class models.Newspaper, data={name=Toledo Blade, rate=10}, value=Some(models.Newspaper@2df64761), errors={})
  </code></pre>
  
  <p>Any reason why the data wouldn't be passed to the Newspaper model?</p>