Employee, the persistence provider will delete the corresponding row from the SKILL table in the database.
The preceding descriptions cover many of the common cases of mapping between domain classes and normalized database schema. More complex domain classes can also map to more elaborate database schema.
PERSISTENCE API The ORM API provides interfaces that represent the runtime environment. The primary interface of the API
E mbedded Mapping A Employee -homeAddress1 : String -homeAddress2 : String -homeCity : String -homeState : String -homeZip : String
<<table>>
EMPLOYEE
-HOME_ADDRESS1 : char varying -HOME_ADDRESS2 : char varying -HOME_CITY : char varying -HOME_STATE : char varying -HOME_ZIP : char varying
B
Employee -homeAddress
Address
-address1 : String -address2 : String -city : String -state : String -zip : String
encapsulates the connection to the database, the query generator, and a cache of domain instances that have been referenced by the application. For this article, this interface is called Session. (In different APIs, this interface is called EntityManager or PersistenceManager, but regardless of the name, it serves the same purpose.)
In a multiuser environment, multiple Session instances are used to isolate users from each other. Each Session has its own connection to the database and its own cache of domain instances. The session cache implements uniquing. If the API supports multiple threads operating on the same Session, all such threads share changes to the domain objects managed by the Session.
The application obtains a Session from a SessionFactory, which encapsulates the data source (connection factory) and ORM model. The SessionFactory also typically includes connection pooling and a second-level or global domain object cache, and it handles the interaction with the container. The SessionFactory is the bootstrap instance and is typically looked up from a system service such as JNDI (Java Naming and Directory Interface) or configured via XML or properties.
Database transactions are represented by a Transaction class, an instance of which the application obtains from the Session instance. There is only one active Transaction instance for a Session (a Session can serially begin and complete multiple transactions), and the different interfaces represent a separation of concerns—that is, the application components that begin and complete transactions are separate from application components that access domain instances.
Database queries are represented by a Query class,
instances of which the application obtains from the Ses-
sion. A Query instance encapsulates a specific query and
implements an execute
method that allows the
application to get differ-
ent sets of data from the
database based on different
parameters.
During a unit of work, the application might have made many changes to domain instances, and at the end of the unit of work, the persistence provider applies changes to the database based on changes made to the mapped domain instances.
D ependent Mapping Employee 0 .. 1 -skills : Set<Skill>
0..*
Skill
-category : int4 -type : String -dateAcquired : Date
<<table>> EMPLOYEE -ID : int4
-EMPLOYEE_ID : int4 -CATEGORY : int4 -TYPE : char varying -DATE_ACQUIRED : date
References:
Archives