Java Reference
In-Depth Information
private Long id;
private boolean booked;
//bi-directional many-to-one association to
SeatType
@ManyToOne [1]
@JoinColumn(name="seat_id") [2]
private SeatType seatType;
// Getters and Setters omitted for
brevity
}
As you can see, the
Seat
entity has the corresponding
@ManyToOne [1]
an-
notation, which naturally complements the
@OneToMany
relationship. The
@JoinColumn [2]
notifies the JPA engine that the
seatType
field is mapped
through the foreign key of the database's seat ID.
Adding JavaBeans Validation
JavaBeans Validation
(
JSR-303 Bean Validation
) is a new validation model avail-
able as part of the Java EE 6 platform. The Bean Validation model is supported
by constraints in the form of annotations placed on a field, method, or class of a
JavaBeans component, such as a managed bean.
In our example, the
SeatType
entity will be created using an input form; therefore,
we will need to validate the data that has been entered by the user.
In our example, we will place a
@javax.validation.constraints.NotNull
constraint on every field that is part of the
SeatType
entering form, and a more
complex constraint on the
description
field, which will set the maximum size
for the seat description to 25 (
@javax.validation.constraints.Size
con-
straint)
and
allow
just
letters
and
spaces
in
it
(
@javax.validation.constraints.Pattern
constraint).