Java Reference
In-Depth Information
private int price;
private int quantity;
//bi-directional many-to-one association to
Seat
@OneToMany(mappedBy="seatType",
fetch=FetchType.EAGER) [4]
private List<Seat> seats;
// Getters and Setters omitted for brevity
}
The first meaningful annotation is
@Entity [1]
, which declares the class as
Entity
. The
@Table [2]
annotation is used to map the bean class with a data-
base table.
The
@Id
annotation,
[3]
, is a mandatory one; it describes the primary key of the
table. Along with
@Id
, there is the
@GeneratedValue
annotation. This is used to
declare that the database is in charge of generating the value.
Moving along, the
@OneToMany
annotation
[4]
defines an association with one-to-
many multiplicity. Actually, the
SeatType
class has many seats. The corresponding
Seat
reference is contained in a list collection.
Finally, note that we have not included here, for the sake of brevity, the field getters
and setters that have been generated.
Let's have a look at the
Seat
entity.
@Entity
public class Seat implements Serializable {
private static final long serialVersionUID =
1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)