Java Reference
In-Depth Information
own set of annotations defined in the package
javax.persistence
to “mark up” entity
classes to be loaded and/or persisted. A JPA Entity Class might look like
Example 23-15
:
Example 23-15. Person.java: JPA annotations
@Entity
public
public class
class
Person
Person
{
int
int
id
;
protected
protected
String firstName
;
protected
protected
String lastName
;
public
public
Person
() {
// required by JPA; must code it since we need 2-arg form.
}
public
public
Person
(
String firstName
,
String lastName
) {
this
this
.
firstName
=
firstName
;
this
this
.
lastName
=
lastName
;
}
@Id @GeneratedValue
(
strategy
=
GenerationType
.
AUTO
,
generator
=
"my_poid_gen"
)
public
public
int
int
getId
() {
return
return
id
;
}
public
public
void
void
setId
(
int
int
id
) {
this
this
.
id
=
id
;
}
public
public
String
getFirstName
() {
return
return
firstName
;
}
public
public
void
void
setFirstName
(
String firstName
) {
this
this
.
firstName
=
firstName
;
}
@Column
(
name
=
"surname"
)
public
public
String
getLastName
() {
return
return
lastName
;
}
public
public
void
void
setLastName
(
String lastName
) {
this
this
.
lastName
=
lastName
;
}