The tutorial example uses the join table strategy to map an inheritance relationship of Pet, which is the base class for Cat and Dog.
With the join table strategy there is a table per class in the hierarchy, but the subclass tables only have the extra attribute they define in their subclass. A discriminator column is NOT required to differentiate between which class type is persisted in a particular row unlike the single table mapping. The persistence manager does not need a discrimiator column to figure out the type.
This is what the annotations look like for Pet.
@Entity @Inheritance(strategy = InheritanceType.JOINED) public class Pet implements java.io.Serializable {
@Entity @Inheritance(strategy = InheritanceType.JOINED) public class Dog extends Pet {
public List findByWeight(double weight) { return manager.createQuery("from Pet p where p.weight < :weight").setParameter("weight", weight).getResultList(); }
Even though the findByWeight method queries on Pet, either Dog or Cat instances can be returned.
create table PET ( ID integer primary key, ANIMAL_TYPE varchar, NAME varchar, WEIGHT double ); create table CAT ( ID integer primary key, LIVES int ); create table DOG ( ID integer primary key, NUMBONES int );
To load subclasses the persistence manager must before a SQL join. This is less efficient than the single table strategy as the SQL query is more complicated.
Unix: $ export JBOSS_HOME=<where your jboss 4.0 distribution is> Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is> $ ant $ ant run run: [java] 2004-10-07 00:16:20,395 INFO org.jboss.remoting.InvokerRegistry[main] - Failed to load soap remoting transpo rt: org/apache/axis/AxisFault [java] Sox [java] Junior
The INFO message you can ignore. It will be fixed in later releases of JBoss 4.0.