Java Reference
In-Depth Information
4.
The
compose
method takes the following steps:
a.
It either creates and persists the
SetupOffice
entity or finds it by primary
key.
b.
It uses the entity to store the equipment or the office information in the data-
base, calling either the
doEquipmentList
or the
doOfficeNumber
busi-
ness method.
c.
If the business method returns
true
, meaning that all of the information has
been stored, it creates a connection and a session, retrieves the reply destina-
tion information from the message, creates a
MessageProducer
, and sends
a reply message that contains the information stored in the entity.
d.
It removes the entity.
Coding the Entity Class for the
clientmdbentity
Example
The
SetupOffice
class,
clientmdbentity-ejb/src/java/eb/SetupOf-
fice.java
, is an entity class. The entity and the message-driven beans are packaged
together in an EJB JAR file. The entity class is declared as follows:
@Entity
public class SetupOffice implements Serializable {
The class contains a no-argument constructor and a constructor that takes two arguments,
the employee ID and name. It also contains getter and setter methods for the employee ID,
name, office number, and equipment list. The getter method for the employee ID has the
@Id
annotation to indicate that this field is the primary key:
@Id
public String getEmployeeId() {
return id;
}
The class also implements the two business methods,
doEquipmentList
and
doOf-
ficeNumber
, and their helper method,
checkIfSetupComplete
.
The message-driven beans call the business methods and the getter methods.
The
persistence.xml
file for the entity specifies the most basic settings:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"