How to use Entity tag with objects that extend another class? (Spring & Hibernate)
<p>I have an abstract class <code>User</code> which is extended by <code>RegularUser</code> and <code>BusinessUser</code>. The tables in MySQL are <code>RegularUser</code> and <code>BusinessUser</code>. I created the abstract <code>User</code> class as both <code>RegularUser</code> and <code>BusinessUser</code> contain similar data.</p>

<p>So if I were to have the Id annotation in the <code>User</code> class like so:</p>

<pre><code>public abstract class User {
    @Id
    @Column(name="id")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long userId;
    // ...
}
</code></pre>

<p>And the Entity/table declaration in the <code>BusinessUser</code> and <code>RegularUser</code> classes like this:</p>

<pre><code>@Entity
@Table(name="BUSINESS_USER")
public class BusinessUser extends User {
    // ...
}
</code></pre>

<p>and this:</p>

<pre><code>@Entity
@Table(name="REGULAR_USER")
public class RegularUser extends User {
    // ...
}
</code></pre>

<p>Would this work properly? Or do both declarations need to be in the same class? Is this possible/allowed? I'm simply a bit confused on how to approach this.</p>