title: Multiple writable mappings exception in EclipseLink
body: <p>I have these tables:</p>
  
  <p><img src="https://i.stack.imgur.com/dFgyP.png" alt="tables"></p>
  
  <p>Which my intention is : A user can be a <code>company</code> or a <code>person</code> but each one of them have something in common, as username which is the <code>email</code> and <code>password</code>, so I used the JPA Tools to generate the entities from the table which result on this:</p>
  
  <pre><code>public class User implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
  
      private String email;
  
      private String password;
  
      private int reputation;
  
      //bi-directional one-to-one association to Company
      @OneToOne(mappedBy="user", cascade={CascadeType.ALL})
      private Company company;
  
      //bi-directional many-to-one association to Location
      @OneToMany(mappedBy="user")
      private List&lt;Location&gt; locations;
  
      //bi-directional one-to-one association to Person
      @OneToOne(mappedBy="user")
      private Person person;
  
      //bi-directional many-to-one association to Product
      @OneToMany(mappedBy="user")
      private List&lt;Product&gt; products;
  
      //bi-directional many-to-one association to UserType
      @ManyToOne
      @JoinColumn(name="type")
      private UserType userType;
  
      //bi-directional many-to-one association to UserPhone
      @OneToMany(mappedBy="user")
      private List&lt;UserPhone&gt; userPhones;
  
      //bi-directional many-to-one association to UserPicture
      @OneToMany(mappedBy="user")
      private List&lt;UserPicture&gt; userPictures;
  
      //bi-directional many-to-one association to UserSocialNetwork
      @OneToMany(mappedBy="user")
      private List&lt;UserSocialNetwork&gt; userSocialNetworks;
  
          // getter and setters
  
  }
  </code></pre>
  
  <p>Now if I try to persist an user object launchs the follow exception in EclipseLink:</p>
  
  <pre><code>Exception [EclipseLink-48] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DescriptorException
  Exception Description: Multiple writable mappings exist for the field [COMPANY.id_user].  Only one may be defined as writable, all others must be specified read-only.
  Mapping: org.eclipse.persistence.mappings.OneToOneMapping[user]
  Descriptor: RelationalDescriptor(entity.Company --&gt; [DatabaseTable(COMPANY)])
  Exception [EclipseLink-48] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DescriptorException
  Exception Description: Multiple writable mappings exist for the field [PERSON.id_user].  Only one may be defined as writable, all others must be specified read-only.
  Mapping: org.eclipse.persistence.mappings.OneToOneMapping[user]
  Descriptor: RelationalDescriptor(entity.Person --&gt; [DatabaseTable(PERSON)])
  Runtime Exceptions: 
  </code></pre>
  
  <p>Is the generated mapping wrong ?
  How can I solve this exception ?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>public class Company implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="id_user")
      private int idUser;
  
      private String email;
  
      private String name;
  
      //bi-directional many-to-one association to Area
      @ManyToOne
      @JoinColumn(name="area")
      private Area areaBean;
  
      //bi-directional one-to-one association to User
      @OneToOne(cascade={CascadeType.ALL})
      @JoinColumn(name="id_user", insertable=false, updatable=false)
      private User user;
  
          // getter and setters
  }
  
  @Entity
  public class Person implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="id_user")
      private int idUser;
  
      @Temporal( TemporalType.DATE)
      private Date birthdate;
  
      private String gender;
  
      private String name;
  
      private String surname;
  
      //bi-directional one-to-one association to User
      @OneToOne
      @JoinColumn(name="id_user", insertable=false, updatable=false)
      private User user;
  
          // getters and setters
  }
  </code></pre>