JB167 Hibernate Essentials
The Hibernate Essentials course is for individuals who must become competent with the Hibernate or the Java Persistence API object/relational persistence and query service.
The primary audience is intended to be Java developers who work with SQL-based database systems or database developers who are looking for an introduction to object-oriented software development. Database administrators who are interested in how ORM may affect performance and how to tune the performance of the SQL database management system and persistence layer will also find this course of value. This course covers the JBoss, Inc. implementation of the JSR-220 sub-specification for Java Persistence and it covers the foundational APIs of version 3.x of the JBoss, Inc. Hibernate product, or simply, Hibernate 3. The Hibernate Essentials course is a prerequisite to the Advanced Hibernate course and the student must attend the Hibernate Essentials course before taking the Advanced Hibernate, or pass the Hibernate Placement Exam.
Course Duration: This is a 3 day course.
Course Format: The format is 50% theory and 50% hands-on lab exercises.
Course Prerequisites
The prerequisite skills for this class are the following:
- An understanding of the relational persistence model
- Competency with the Java language
- Knowledge of OOAD concepts
- Familiarity with the UML Experience with a dialect of SQL
- Using the JDK and creating the necessary environment for compilation and execution of a Java executable from the command line
- An understanding of JDBC
Course Modules
The Hibernate Essentials course is recommended for Java developers who must become competent with a Hibernate or a Java Persistence API object/relational persistence and query service implementation. Both implementations provide powerful APIs to develop persistent classes following the object-riented idiom. Both implementations support the use of association, inheritance, polymorphism, composition and collections with persistent classes. To fully utilize persistent class implementations, the student will also learn how to create and execute queries using EJB-QL, the portable Hibernate SQL extension (HQL), native SQL and the object-oriented Criteria and Example API.
Understanding object/relational persistence
In this module persistent data management in the context of object-oriented applications is defined. The relationship of SQL, JDBC and Java, specifically the underlying technologies and standards that Hibernate is built upon, is discussed. The software development challenges that embody the "object/relational paradigm mismatch" are individually identified. Additional generic problems that are encountered when creating object-oriented software clients to relational databases are also discussed. This module concludes with presenting the transparent and automatic object/relational mapping capabilities provided by JPA and Hibernate as two existing options that can be used to overcome the object/relational paradigm mismatch problem.
Getting started with Hibernate
This module provides the student with the information necessary to begin a Hibernate project. The student is guided through selecting a development process, setting up a project, authoring the necessary configuration files and java classes and running and testing the application. Once the basic skills are mastered, the student is presented with realistic use cases such as writing a hibernate client to an existing legacy database. The Hibernate reverse engineering tools are presented to the student in the context of this use case. The module concludes with an introduction to using JPA/Hibernate annotations and using the JPA/Hibernate EntityManager.
Domain models and metadata options
In this section, the student is introduced to the on-line auction application, "CaveatEmptor". This application will be used throughout the course lecture and the course labs to provide realistic JPA and Hibernate use cases. The student will walk through implementing the domain model. Sound design patterns and development practices for persistent classes will presented. The student will learn how to address the leakage of concerns, how to implement transparent and automated persistence, how to use established design patterns when working with plain ordinary/old, Java objects (POJOs) as business objects, value objects and entities and how to implement POJO associations. This module will conclude with the object/relational mapping metadata. Metadata will be presented as XML and as annotation-based. In addition the student will be exposed to useful technologies and skills such as XDoclet, handling global metadata and manipulating metadata at runtime.
Mapping persistent classes
This module focuses on mapping entities with XML and annotations, fine-grained property and component mappings and inheritance mapping strategies. The first section defines the essential distinction between entities and value types and how an individual should approach the object/relation mapping of a given domain model. The module continues with the presentation of fundamental mapping options to show how classes and properties are mapped to tables and columns. The student will learn how to handle database identity and primary keys and how to use metadata settings to influence the loading and storing of objects. Mapping examples are presented in both Hibernate's native XML format and with JPA annotations and XML descriptors. Fine-grained domain models are examined and the student is shown how properties and embedded components are mapped. The module concludes by providing guidelines for choosing the appropriate inheritance mapping strategy when mapping object inheritance hierarchies.
Collections and Associations
Most developers new to object/relational mapping techniques have their first experience working with collections and entity associations with the mapping of a parent/child relationship. It is for this reason that there many examples of this relationship in the CaveatEmptor domain and, it is for this reason that this association is the focus of this module. In this section the student will learn how to map "one" and "many"-valued relationships between entity classes. The ability for other classes to have an association to the same target class (not only a single entity class) and the fact that each entity target instance has its own identity and independent state complicates what is initially perceived as a "simple" relationship mapping. This module guides the student through these issues (which includes bidirectional associations and cascading parent to child state) step by step.
Working with objects
In this module the student will learn greater detail about the lifecycle and states of objects, the Hibernate persistence manager API, EJB3 and the Java Persistence API and data filtering and interception. The module begins by describing how an object becomes persistent and how it stops being considered persistent or, more specifically, the method calls and other actions that trigger these transitions. As the Hibernate persistence manager is responsible for managing object state the student is exposed to this API first. The main Java Persistence interface in EJB 3.0 is called EntityManager and, due to its close resemblance to Hibernate API, the EM API is taught in concert with the Hibernate API. This module concludes with a discussion of data filtering and interception. Both of these capabilities offer transparent "hooks" into the loading and storing process inside the Hibernate engine. The student will learn how to influence or participate in the lifecycle of Hibernate and JPA objects without writing complex application code or without binding the domain model to the persistence mechanism.
Transactions
This module provides a comprehensive treatment of transactions. The student will understand how to create and control units of work in an application. How transactions work at the database level will also be covered. The student will learn how to work with transactions in an application that is based on native Hibernate, Java Persistence or the EJB container. The student will understand how to demarcate a transaction boundary to define a unit of work. Concurrency and how concurrent data access can be controlled in an application with pessimistic and optimistic strategies will be the final topic of this section.
Efficient storing and loading
This module covers transitive state changes, batch and bulk processing and applying global fetching strategies. The student is introduced to techniques for efficient storing and loading of objects. The student will learn how to optimize and reduce the amount of code that is necessary to store objects and how to identify the most efficient data retrieval and processing options. The student will be shown how transitive persistence can facilitate working with complex object networks. The student will understand how enabling cascading options in Hibernate and Java Persistence applications will significantly reduce the amount of code that is needed to insert, update, or delete, several objects at a time. The module addresses object retrieval in detail and discusses how large datasets are best handled with applicationoriented batch operations or with bulk operations that execute directly on the database. The module concludes with a discussion of fetching strategies and how their use can optimize the loading of object networks when an application navigates from one object to another object.
Querying
Upon completion of this module the student will understand how to work with the various query options available via the Hiberate and JPA APIs. The student will learn how to write and execute HQL and EJBQL queries. The Criteria and Example APIs will also be presented. This module concludes by showing the student how to embed native SQL and stored procedures in a query.
Application design and architecture
This module covers creating layered applications with or without the use of managed components and services. The module concludes recommended testing practices with applications with persistence. The student will be presented with common Java architectures to illustrate how Hibernate can be integrated into various scenarios. In the first part of this module, domain modelling and application layering is discussed as creating layers may affect persistence-related code. Persistence in rich clients and desktop applications is briefly addressed. Many of the patterns and strategies shown are generic. They can be implemented in any framework as well as simple JSE. JEE services and EJBs are introduced to show how managed components can facilitate and reduce the amount of infrastructure coding. The simplicity of the new EJB 3.0 specification, in particular, allows the developer to benefit greatly from a container environment. The module concludes with testing layered applications with or without managed components. Unit-, functional- and integration testing are addressed by using the testing framework, TestNG