If you are using Hibernate Annotations, you would do the following.
Code:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class TopClass {
// all shared properties and methods, id
}
@Entity
@Table(name="TABLE_A")
public class SubClassA extends TopClass {
// empty class body
}
@Entity
@Table(name="TABLE_B")
public class SubClassB extends TopClass {
// empty class body
}
After that, Hibernate will always know which table to access when you create instances of, or query for, SubClassA or SubClassB. It's that simple!