title: Hibernate and two classes mapped to single table
body: <p>I have a single table that has multiple attributes.
  I want to have a two classes for accessing those (exclusive) attributes.</p>
  
  <pre><code>@Entity
  @Table(name = "MY_TABLE")
  public class Foo {
  
  ...
      @Column
      @NotNull
      private String fooValue; 
  }
  
  @Entity
  @Table(name = "MY_TABLE")
  public class Bar {
  ...
      @Column
      private String barValue; 
  ...
  }
  </code></pre>
  
  <p>Basically <code>Bar</code> is a read only view on <em>some</em> of the values in a table. <code>Foo</code> is used to update other values and <code>Bar</code> is used to view other values (that are created not using Java application).</p>
  
  <p>The trouble is that when I try to save <code>Foo</code> using Spring Data repository:</p>
  
  <pre><code>public interface FooRepository extends JpaRepository&lt;Foo, Long&gt; {
  }
  </code></pre>
  
  <p>I get exception that <code>fooValue</code> is set to <code>null</code>. And I see in logs an insert with <code>NULL</code> for <code>fooValue</code>. I debugged it a little and when I remove <code>Bar</code> completly from the project the save works, when I add it again save of <code>Foo</code> stops working.</p>
  
  <p>So for me it looks like Hibernate picks up <code>Bar</code> class even when I try to save <code>Foo</code>. Why?</p>
  
  <p>My stack is: Spring Boot 1.5.3, Spring Data, Hibernate 5.x</p>