Java Reference
In-Depth Information
primary key. To use
@EmbeddedId
to map this, the first thing you'll do in the following
listing is create an
@Embeddable CategoryId
class to represent this primary key.
Listing 9.9.
CategoryId
As you can see, this listing is nearly identical to
listing 9.8
.
The important difference
is the use of the
@Embeddable
annotation in
CategoryId
. By using
@Embed-
dable
, you're telling JPA the
CategoryId
class can be put into or embedded into
other classes. The
name
and
createDate
properties still make up the primary key.
The
CategoryId
class has a required no-argument constructor
. It overrides the
equals()
method
, which does the test for equality, and it has a required overridden
hashCode()
method
.