Chapter 6 Flashcards
objects vs. relational dbs
structure:
complex values, ollections, class hierarchies(inheritance) vs. flat tables
relationships: binary, 1:1, 1:n, n:m (using collections), uni-b-directional references vs. binary, 1:1, 1:n, value-based, symmetric
behavior: methods vs. NOTHING
access paradigm: objcect navigation (follow references) vs. declarative, set-oriented (queries)
Object relational mappping:
- Object class: to single table or to multiple tables to support inheritance and complex field values
- object reference as foreing key constraint
- instance object to one or more rows in a table
- data types and values need to consider variable length data (strings), differences in the type models, semantics
- mapping tool support: top-down, bottom-up; meet-in-the-middle
The CRUD pattern
create, read/retrieve, update, delete
What are the aspects of persistence?
Orthogonal persistence (persistence independent of data type class. Instance of the same class may be transient or persistent) Transitive persistence (persistence by reachability). Objects can be explicitly designed to become persistent and objects referenced by persisted objects are automatically persisted Persistence independence (transparent persistence) (code on transient and persistent objects is almost the same. Application may have to explicit persist an OBJECT and the interactions with a data store are not visible to the client object (it happens automatically when object is modified or at EOT)
Java persistence api - JPA
Java standard for persistence framework
result of a major „overhaul“ of EJB specification for persistence, relationships, and query support
It can be used from within an EJB environment/container or outside EJB,e.g., withing a standard JAVa SE application.
Entities is JPA is a POJO (plain old java object).
Class has to be designated (annotated) as entity class Mapping of Meta-data are done by use of annotations for persistence and relationship aspect or, alternatively, XML deployment descriptor. Abstract and concrete classes can be entities
Inheritance mapping strategies
See chap 6 slide 15 *single table with discriminator column (default) *Horizaontal partitioning (single table per concrete entity class) Vertical partitioning (separate table per subclass)
Name advantages and disadvantages of each inheritance mapping strategies:
Single table with discriminator column: Adv: everything in a single table. Simple and fast to query. Disadv: A lot of unnecessary space in database is used because of the empty columns.
Horizontal partitioning: adv: solve the problems of use of unecessary space in database. Disadvantage: More tables, more complex.
Vertical partitioning. The same as horizontal partitioning. BUt the data must always be collected from multiple tables, meanwhile in horizontal partitioning it’s possible to collect data from a specific class directly from its specific table.
which are the inheritance mapping strategies?
Single table with discriminator column:, Horizontal partitioning:, Vertical partitioning.
Automatic Persistence. What are the strategies for loading objects from the persistent store during navigational access?
Lazy loading - object is retrieved when accessed based on primary key or reference
Eager loading - when an object is requested, transitively load all the object reachable through references. May cause a lot of unnecessary objects to be loaded.
In order to write object changes back to the data store you have immediate update and deferred update. Explain them:
- immediate update (many interactions with the DBMS)
- Deferred update (record changes and combine them into a single update per tuple at the end of the transaction)(write back changes also before any object query statements are executed)
What are the concurrency control strategies?
Pessimistic (locking at the DBMS-level) Optimistic locking (inconsistencies may arise if entities are not protected by a version attribute; it does not guarantee consistent reads; conflicts can only be detected at the end of a transaction)