Here is the scenario. I have Class A and Class B. B extends A in Java. Each has it's own table with it's own set of columns. Example:
Code:
@Entity
@Table(name="MyA")
public Class A
{
private firstName;
private lastName;
public String getFirstName()
{...}
public void setFirstName(...)
{...}
public String getLastName()
{...}
public void setLastName(...)
{...}
}
@Entity
@Table(name="MyB")
public Class B extends A
{
private middleName;
public String getMiddleName()
{...}
public void setMiddleName(...)
{...}
}
Table MyA has columns [id,firstName,lastName], Table MyB has columns [id,firstName,lastName,middleName]
Initially, without a inheritance strategy, it wants to look in the same table for both. I decided to use a inheritance strategy of TABLE_PER_CLASS, but this causes problems when I try to get a count of Class B.
Example
select count(myB) from B myB; --returns the count of the union of myA and myB.
I really just want to treat class myB has it's own entity. I figure one solution is to create a MappedSuperClass with the common columns, then extend it in the other classes. I was just wondering if there is a shortcut. Can I extend a class, but tell hibernate not to use an inheritance strategy? Hope this isn't a stupid question! Thanks in advance for your help!