background image

Temporal Types in the order Application

<< Cascade Operations in the order Application | Setting Entity Relationships >>
<< Cascade Operations in the order Application | Setting Entity Relationships >>

Temporal Types in the order Application

SPECIFICATION
is mapped to the field Part.specification of type java.lang.String. The
@Lob
annotation is also used here to denote that the field is a large object.
@Column(table=
"EJB_ORDER_PART_DETAIL")
@Lob
public String getSpecification() {
return specification;
}
Both of these fields use the @Column annotation and set the table element to the secondary
table.
Temporal Types in the order Application
The Order.lastUpdate persistent property, which is of type java.util.Date, is mapped to the
EJB_ORDER_ORDER.LASTUPDATE
database field, which is of the SQL type TIMESTAMP. To ensure
the proper mapping between these types, you must use the @Temporal annotation with the
proper temporal type specified in @Temporal's element. @Temporal's elements are of type
javax.persistence.TemporalType
. The possible values are:
DATE
, which maps to java.sql.Date
TIME
, which maps to java.sql.Time
TIMESTAMP
, which maps to java.sql.Timestamp
Here is the relevant section of Order:
@Temporal(TIMESTAMP)
public Date getLastUpdate() {
return lastUpdate;
}
Managing the order Application's Entities
The RequestBean stateful session bean contains the business logic and manages the entities of
order
.
RequestBean
uses the @PersistenceContext annotation to retrieve an entity manager instance
which is used to manage order's entities in RequestBean's business methods.
@PersistenceContext
private EntityManager em;
This EntityManager instance is a container-managed entity manager, so the container takes
care of all the transactions involved in the managing order's entities.
The order Application
Chapter 26 · Persistence in the EJB Tier
719