Java Reference
In-Depth Information
annotation; then we'll look at some features added in JPA 2.0 that make mapping columns
easier and more flexible for objects in your domain model. Finally, we'll discuss transient
fields in more detail.
@Column annotation
Let's start by looking at an example of how you'd map some properties from the User
entity in listing 9.2 , as shown in the following listing.
Listing 9.3. Mapping User entity properties
This listing shows the @Column annotation specifying which column from the USERS
table the property should map to. So, for the userId property, it's assumed a USER_ID
column exists in the USERS table and JPA will store that database data in userId . The
username property is similar—JPA assumes a USER_NAME column exists in USERS
.
The email property is different. The email property doesn't have a @Column annota-
tion . So how does JPA know how to map it? Remember the Java EE preference for con-
vention over configuration? By convention, JPA saves all Java object properties that have
JavaBeans-style public or protected setters and getters and by default assumes the column
name is the same as the property name. The email property has the standard getter and
setter methods, so JPA will, by default, automatically try to persist it
. Because the name
 
Search WWH ::




Custom Search