Skip to main content

2015 | Buch

Hibernate Recipes

verfasst von: Joseph Ottinger, Srinivas Guruzu, Gary Mak

Verlag: Apress

insite
SUCHEN

Über dieses Buch

Hibernate Recipes, Second Edition contains a collection of code recipes and templates for learning and building Hibernate solutions for you and your clients, including how to work with the Spring Framework and the JPA. This book is your pragmatic day-to-day reference and guide for doing all things involving Hibernate. There are many books focused on learning Hibernate, but this book takes you further and shows how you can apply it practically in your daily work. Hibernate Recipes, Second Edition is a must have book for your library.

Hibernate 4.x continues to be the most popular out-of-the-box, open source framework solution for Java persistence and data/database accessibility techniques and patterns and it works well with the most popular open source enterprise Java framework of all, the Spring Framework. Hibernate is used for e-commerce–based web applications as well as heavy-duty transactional systems for the enterprise.

Inhaltsverzeichnis

Frontmatter
Chapter 1. Starting with Hibernate
Abstract
An object model uses the principles of abstraction, encapsulation, modularity, hierarchy, typing, concurrency, polymorphism, and persistence. The object model enables you to create well-structured and complex systems. In an object model system, objects are the components of the system. Objects are instances of classes, and classes are related to other classes via inheritance relationships. An object has an identity, a state, and a behavior. An object model helps you create reusable application frameworks and systems that can evolve over time. In addition, object-oriented systems are usually smaller than non-object-oriented implementations.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 2. Basic Mapping and Object Identity
Abstract
A primary key in a database table is used to uniquely identify a record in that table. The primary key value can't be null and is unique within a table. The primary key is also used to establish a relationship between two tables; it is defined as a foreign key in the associated table. Because the primary key is used to identify a particular record, it can also be called the database identifier, which is exposed to the application by Hibernate through an identifier property of the persistent entity. This chapter discusses the various ways to generate an identifier (primary key) for a database record. You learn about metadata configurations and their effect on the persistence mechanism.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 3. Component Mapping
Abstract
Hibernate makes it easy to employ a fine-grained domain model so you can have more classes than tables. In other words, you can map a single record in a table to more than one class by having one Entity class type; the others should be Value class types.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 4. Inheritance and Custom Mapping
Abstract
Inheritance, polymorphic associations, and polymorphic queries are supported by entities. The JPA specification says that both concrete and abstract classes can be entities and can be mapped with the Entity annotation. Non-entity classes and entity classes can extend each other. Hibernate provides the MappedSuperclass annotation (@MappedSuperclass) to enable inheritance mapping and to let you map abstract or concrete entity subclasses. The mapped superclass doesn't necessarily have its own separate table.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 5. Many-to-One and One-to-One Mapping
Abstract
In general, entities are related or associated to each other. For example, a Customer entity is associated with an Address entity. A Customer entity can have one or more than one Address entity (for example, Billing and Shipping). These relationships or associations are represented differently in a relational model and the domain/object model.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 6. Collection Mapping
Abstract
Collection mapping refers to the concept of an object in the database—an entity—that possesses references to a set of other objects, none of which exists outside the context of the owning object. An example is an order line item: an order has many line items, although it might exist without any. However, because a line item does not have any way to exist outside of the context of its order, the order might be said to have a collection of line items.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 7. Many-Valued Associations
Abstract
A many-valued association is by definition a collection of references to entities. The collection can be of type List, Set, Map, and so on in Java.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 8. HQL and JPA Query Language
Abstract
When you use JDBC to access databases, you write SQL statements for the query and update tasks. In such cases, you’re dealing with tables, columns, and joins. When you use Hibernate, most update tasks can be accomplished through the provided APIs. However, you still need to use a query language for the query tasks, and Hibernate provides a powerful query language called Hibernate Query Language (HQL).
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 9. Querying with Criteria and Example
Abstract
In the previous chapter, you saw how to use Hibernate Query Language (HQL) and Java Persistence Query Language (JPA QL). HQL forces you to interact with the database using SQL-like syntax. You must have some knowledge of SQL to create complex queries, which makes it difficult to develop applications that use multicriteria queries.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 10. Working with Objects
Abstract
This chapter discusses the states an object goes through during its life cycle. The session is responsible for managing object state in Hibernate, and the EntityManager does the same in Java Persistence. Hibernate provides a persistence mechanism that is transparent to the entities and the application; the application has to know the state of an object.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 11. Batch Processing and Native SQL
Abstract
is the processing of groups of elements. From an application standpoint, batch processing means reading data from a persistent store, doing something with the data, and then possibly storing the processed data in the persistent store as a single conceptual operation. Batch processing, which allows for the automation and sharing of computer resources, is usually run when computer resources are less busy.
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 12. Caching in Hibernate
Abstract
Caching is one of the important features implemented by an application for better performance. From an ORM perspective, data retrieved from a database is cached in memory or to disk, so there is no need to make a call to the database for every request. A cache is a local copy of the information from the database that can be used to avoid a database call whenever the following situations occur:
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 13. Transactions and Concurrency
Abstract
Let’s say that a buyer logs in to the bookshop application and purchases a book. The following actions should take place in the event of a purchase:
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Chapter 14. Web Applications
Abstract
So far, you've seen a lot of aspects of working with data, and it's time to look at one way to use Hibernate to access data over the Web, which is (obviously) a very common access method. (If it's not obvious, trust me: it's obvious.)
Joseph Ottinger, Srinivas Guruzu, Gary Mak
Backmatter
Metadaten
Titel
Hibernate Recipes
verfasst von
Joseph Ottinger
Srinivas Guruzu
Gary Mak
Copyright-Jahr
2015
Verlag
Apress
Electronic ISBN
978-1-4842-0127-5
Print ISBN
978-1-4842-0128-2
DOI
https://doi.org/10.1007/978-1-4842-0127-5