background image

SummerLeague Class

<< Entity Inheritance in the roster Application | Automatic Table Generation >>
<< Entity Inheritance in the roster Application | Automatic Table Generation >>

SummerLeague Class

implements java.io.Serializable {
/** Creates a new instance of SummerLeague */
public SummerLeague() {
}
public SummerLeague(String id, String name,
String sport) throws IncorrectSportException {
this.id = id;
this.name = name;
if (sport.equalsIgnoreCase(
"swimming") ||
sport.equalsIgnoreCase(
"soccer") ||
sport.equalsIgnoreCase(
"basketball") ||
sport.equalsIgnoreCase(
"baseball")) {
this.sport = sport;
} else {
throw new IncorrectSportException(
"Sport is not a summer sport.");
}
}
}
The roster application uses the default mapping strategy of InheritanceType.SINGLE_TABLE,
so the @Inheritance annotation is not required. If you wanted to use a different mapping
strategy, decorate League with @Inheritance and specify the mapping strategy in the strategy
element:
@Entity
@Inheritance(strategy=JOINED)
@Table(name=
"EJB_ROSTER_LEAGUE")
public abstract class League implements java.io.Serializable {
...
}
roster
uses the default discriminator column name, so the @DiscriminatorColumn annotation
is not required. Because you are using automatic table generation in roster the Persistence
provider will create a discriminator column in the EJB_ROSTER_LEAGUE table called DTYPE,
which will store the name of the inherited entity used to create the league. If you want to use a
different name for the discriminator column, decorate League with @DiscriminatorColumn
and set the name element:
@Entity
@DiscriminatorColumn(name=
"DISCRIMINATOR")
@Table(name=
"EJB_ROSTER_LEAGUE")
public abstract class League implements java.io.Serializable {
...
}
The roster Application
The Java EE 5 Tutorial · September 2007
728