title: Mapping a weak entity with JPA
body: <p>My database contains a companies and employees. I have modeled Employee as a weak entity of Company.</p>
  
  <p>My JPA annotations look like:</p>
  
  <pre><code>@Entity
  public class Company extends Model {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      public Long id;
  
      @OneToMany(mappedBy = "company", cascade = CascadeType.ALL)
      private List&lt;Employee&gt; employees;
  
  }
  </code></pre>
  
  <p>Employee.java:</p>
  
  <pre><code>@Entity
  public class Employee extends Model {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      public Long id;
  
      @ManyToOne(optional = false)
      @JoinColumn(name="company_id", insertable=false, updatable=false)
      private Company company;
  }
  </code></pre>
  
  <p>The following SQL code is created:</p>
  
  <pre><code>create table employee (
    id                            bigint auto_increment not null,
    company_id                    bigint not null,
    constraint pk_employee primary key (id)
  );
  
  alter table employee add constraint fk_employee_company_id foreign key (company_id) references company (id) on delete restrict on update restrict;
  </code></pre>
  
  <p>What I want is (constraint pk_employee primary key (id, <strong>company_id</strong>):</p>
  
  <pre><code>create table employee (
    id                            bigint auto_increment not null,
    company_id                    bigint not null,
    constraint pk_employee primary key (id, company_id)
  );
  
  alter table employee add constraint fk_employee_company_id foreign key (company_id) references company (id) on delete restrict on update restrict;
  </code></pre>
  
  <p>Is there a way to create such SQL script?</p>
  
  <p><strong>EDIT:</strong>
  Letting <code>Employee</code> implement <code>Serializable</code> does not do the trick.</p>
  
  <pre><code>Caused by: javax.persistence.PersistenceException: Could not find BeanDescriptor for class models.Company. Perhaps the EmbeddedId class is not registered?
      at io.ebeaninternal.server.deploy.BeanEmbeddedMetaFactory.create(BeanEmbeddedMetaFactory.java:26)
      at io.ebeaninternal.server.deploy.BeanPropertyAssocOne.&lt;init&gt;(BeanPropertyAssocOne.java:79)
      at io.ebeaninternal.server.deploy.BeanPropertyAssocOne.&lt;init&gt;(BeanPropertyAssocOne.java:62)
      at io.ebeaninternal.server.deploy.meta.DeployBeanTable.createProperty(DeployBeanTable.java:68)
      at io.ebeaninternal.server.deploy.meta.DeployBeanTable.createIdProperties(DeployBeanTable.java:59)
      at io.ebeaninternal.server.deploy.BeanTable.&lt;init&gt;(BeanTable.java:42)
  </code></pre>