title: Play Framework - Ebean - No ScalarType registered for class "class name"
body: <p>I built some tables in MySQL database, using persistence API and Ebean by representing the custom Java Objects as tables. Now, I try to recover the stored entries, by passing as arguments in the Ebean.find() queries the objects I want, but <code>javax.persistence.PersistenceException</code> is thrown every time.</p>
  
  <hr>
  
  <p>Let me explain the hierarchies and structure:</p>
  
  <p>There is a <strong>Machine</strong> class:</p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = "MACHINE_TYPE")
  public class Machine extends Model
  {
      @Id
      @Column(name = "id")
      private Long _machineID;
  
      @Column(name = "name", unique = true)
      private String _name;
  
      @Column(name = "info")
      private String _info;
  
      // rest of code
  }
  </code></pre>
  
  <p>With two subclasses. A <strong>Server</strong> class extending <strong>Machine</strong> as follows:</p>
  
  <pre><code>@Entity
  @Table(name = "machine")
  @DiscriminatorValue("Server")
  public class Server extends Machine
  {
     @Column(name = "ip")
     private String _ip;
  
     @Column(name = "port")
     private Integer _port;
  
     @Column(name = "user_name")
     private String _userName;
  
     @Column(name = "password")
     private String _password;
  
     @Column(name = "clock")
     private Integer _clock;
  
     @Column(name = "ram")
     private Integer _ram;
  
     // rest of code
  }
  </code></pre>
  
  <p>And a <strong>Container</strong> class:</p>
  
  <pre><code>@Entity
  @Table(name = "machine")
  @DiscriminatorValue("Container")
  public class Container extends Machine
  {
  @Column(name = "dockerID", unique = true)
     private String _dockerID;
  
     @ManyToOne
     @JoinColumn(name = "host", insertable = true, updatable = true)
     private Server _host;
  
     @Column(name = "currentSize")
     private String _currentSize;
  
     @Column(name = "additionalInfo")
     private String _additionalInfo;
  
     @Column(name = "last_login")
     private String _lastLogin;
  
     // rest of code
  }
  </code></pre>
  
  <hr>
  
  <p>This code, builds a machine table in MySQL database as follows:</p>
  
  <pre><code>`machine` (
    `machine_type` varchar(31) NOT NULL,
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `name` varchar(255) DEFAULT NULL,
    `info` mediumtext,
    `dockerID` varchar(255) DEFAULT NULL,
    `host` bigint(20) DEFAULT NULL,
    `currentSize` varchar(255) DEFAULT NULL,
    `additionalInfo` text,
    `last_login` varchar(255) DEFAULT NULL,
    `ip` varchar(255) DEFAULT NULL,
    `port` int(11) DEFAULT NULL,
    `user_name` varchar(255) DEFAULT NULL,
    `password` varchar(255) DEFAULT NULL,
    `clock` int(11) DEFAULT NULL,
    `ram` int(11) DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_machine_dockerID` (`dockerID`),
    KEY `ix_machine__host_4` (`host`),
    CONSTRAINT `fk_machine__host_4` FOREIGN KEY (`host`) REFERENCES `machine` (`id`)
  )
  </code></pre>
  
  <p>Which seems correct. But, if I add an entry into the DB and try to execute</p>
  
  <pre><code>...
  Server server = Server.getServerByName(serverName); // this returns a Server object correctly
  List&lt;Container&gt; testCase = Ebean.find(Container.class)
                      .where()
                      .eq("host", server)
                      .findList(); // this throws the exception
  </code></pre>
  
  <p>I got a <code>PersistenceException</code> saying:  </p>
  
  <pre><code>javax.persistence.PersistenceException: No ScalarType registered for class com.project.models.Server
      at com.avaje.ebeaninternal.server.persist.Binder.bindObject(Binder.java:158)
      rest of the StackTrace
  </code></pre>
  
  <p>Even when I try to change the query with</p>
  
  <pre><code>List&lt;Container&gt; testcase = Ebean.find(Container.class)
                      .where()
                      .eq("host", server.getMachineId()) // pass the serverID
                      .findList();
  </code></pre>
  
  <p>I got another exception denoting:</p>
  
  <pre><code>javax.persistence.PersistenceException: Query threw SQLException:Column 'host' in where clause is ambiguous 
  Bind values:[1] 
  Query was:
  select t0.machine_type c0, t0.id c1, t0.name c2, t0.info c3, t0.dockerID c4, t0.currentSize c5, 
  t0.additionalInfo c6, t0.last_login c7, t1.machine_type c8, t0.host c9 from machine t0 
  left outer join machine t1 on t1.id = t0.host and t1.machine_type = 'Server'  
  where t0.machine_type = 'Container'  and host = ?  
  </code></pre>
  
  <hr>
  
  <p>Any help, at least to what direction to follow will be appreciated</p>