title: Hibernate: interesting quiz with insertable=false & updatable=false
body: <p><em><strong>What I have:</em></strong></p>
  
  <p>Multiple <code>Owner</code> entities which hold one of <code>Client</code> subtype entities. I need that each subtype of Client entity can be saved to database only once, so I use <code>insertable = false, updatable = false</code>.</p>
  
  <pre><code>@Entity
  @Table(name = "Client")
  public class Client implements Serializable {
  
      @Id
      @Column(name = "id")
      private String id = this.getClass().getSimpleName();
  
      @Column(name = "firstName")
      private String firstName;
  
      //getters &amp; setters
  }
  
  @Entity
  @Table(name = "Client")
  public class AngryClient extends Client {
  }
  
  @Entity
  @Table(name = "Client")
  public class SilentClient extends Client {
  }
  
  @Entity
  @Table(name = "Owner")
  public class Owner {
  
      @Id
      @SequenceGenerator(name = "sequence", sequenceName = "_vacancy")
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence")
      @Column(name = "id")
      private int id;
  
      @ManyToOne
      @JoinColumn(name = "id", insertable = false, updatable = false)
  
       //getters &amp; setters
  }
  </code></pre>
  
  <p><em><strong>What I can't grasp:</em></strong></p>
  
  <p>Due to <code>insertable = false, updatable = false</code>, when we save the owner, <em>the client won't be saved</em>. It can be easely be checked in database. The <em>only column that is stored in <code>owner</code> table is <code>id</code></em>.</p>
  
  <p><strong>So how does Hibernate know which <code>Client</code> corresponds to which <code>Owner</code>?!</strong></p>
  
  <pre><code>Session session = sessionFactory.openSession();
  session.beginTransaction();
  
  Owner owner1 = new Owner();
  Owner owner2 = new Owner();
  Client client1 = new AngryClient();
  Client client2 = new SilentClient();
  owner1.setClient(client1);
  owner2.setClient(client2);
  session.save(owner1); //client1 isn't saved
  session.save(owner2); //client2 isn't saved
  int owner1Id = owner1.getId();
  session.getTransaction().commit(); //client table is empty
  
  Session session1 = sessionFactory.openSession();
  Owner owner = (Owner) session1.get(Owner.class, owner1Id);
  System.out.println(owner.getClient());  //HOW DOES IT WORK?! (owner.getClient() returns me AngryClient)
  </code></pre>
  
  <p><em><strong>Question:</em></strong></p>
  
  <p>How does it work? Or how Hibernate fill up the client filed when we do <code>session.get(Owner.class, owner1Id)</code>?</p>