Spring Persistence with Hibernate

Build robust and reliable persistence solutions for your enterprise Java application

Spring Persistence with Hibernate

Starting
Ahmad Seddighi

Build robust and reliable persistence solutions for your enterprise Java application
$10.00
$49.99
RRP $29.99
RRP $49.99
eBook
Print + eBook
$12.99 p/month

Get Access

Get Unlimited Access to every Packt eBook and Video course

Enjoy full and instant access to over 3000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

+ Collection
Free Sample

Book Details

ISBN 139781849510561
Paperback460 pages

About This Book

  • Get to grips with Hibernate and its configuration manager, mappings, types, session APIs, queries, and much more
  • Integrate Hibernate and Spring as part of your enterprise Java stack development
  • Work with Spring IoC (Inversion of Control), Spring AOP, transaction management, web development, and unit testing considerations and features
  • Covers advanced and useful features of Hibernate in a practical way

Who This Book Is For

The book is primarily for Spring developers and users who want to persist using the popular Hibernate persistence framework. Java, Hibernate, JPA, Spring, and open source developers in general will also find the book useful.

Table of Contents

Chapter 1: An Introduction to Hibernate and Spring
Persistence management in Java
Object relational mapping
Hibernate as an O/R Mapping solution
Hibernate architecture
What is Spring
Summary
Chapter 2: Preparing an Application to Use Spring with Hibernate
Setting up the database
Getting a Hibernate distribution
Getting a Spring distribution
Setting up the project hierarchy
Setting up Ant or Maven in the project
Summary
Chapter 3: A Quick Tour of Hibernate and Spring
Getting started with Hibernate
Hibernate declarative configuration
Some issues in mapping
Getting started with Spring
Hibernate with Spring
Summary
Chapter 4: Hibernate Configuration
Basic configuration information
Hibernate dialect
Configuring Hibernate
Using a single instance of SessionFactory
JPA configuration
Summary
Chapter 5: Hibernate Mappings
Persistent entity classes
Object/relational mapping metadata
Mapping inheritance hierarchy
Summary
Chapter 6: More on Mappings
Mapping components
Mapping collections
Mapping object associations
Summary
Chapter 7: Hibernate Types
Built-in types
Custom types
Summary
Chapter 8: Hibernate Persistence Behavior
The life cycle of persistent objects
Persistence with Hibernate
Cascading operations
Lazy loading
Some useful Session methods
Summary
Chapter 9: Querying In Hibernate
The Session API and querying
HQL
Bulk updates and bulk deletes with HQL
Queries in native SQL
Named SQL and HQL queries
Using the Criteria API
Paging the query result
Logging the Hibernate-Generated SQL
Summary
Chapter 10: Inversion of Control with Spring
Inversion of Control and dependency injection
Inversion of Control in Spring
Applying IoC to Hibernate resources
PropertyEditors
Summary
Chapter 11: Spring AOP
Introduction to AOP
Using Spring AOP with Spring IoC: An example
Spring's AOP framework
Moving to Spring 2.x's AOP
Summary
Chapter 12: Transaction Management
Transaction essentials
Transactions in Hibernate applications
Spring transaction abstraction
Caching
Summary
Chapter 13: Integrating Hibernate with Spring
The Data Access Object pattern
Service Facade Pattern
Data tier implementation with Hibernate
Data tier implementation with Spring
Spring exception translation
Refactoring DAO classes to use Spring
Configuring Hibernate in a Spring context
Spring transaction management
Summary
Chapter 14: Web Development with Hibernate and Spring
Problem definition
The MVC architectural pattern
Spring MVC web framework
Summary
Chapter 15: Testing
An introduction to unit testing
Unit testing with JUnit
Integration testing data-access layer
Testing Inversion of Control
Unit testing using mocks
Automating tests with Ant
Summary

What You Will Learn

  • Learn the philosophy, the history, and the usage of Persistence
  • Solve problems related to Persistence by gaining a complete understanding of Hibernate
  • Know your competitors and gear yourself to knock down your competition using Hibernate exhaustively
  • Get to know the role of Spring in Persistence and learn to configure Hibernate and Spring
  • Use the essential, most commonly-used Hibernate features such as Transparent persistence, Object-Relational mappings, Object-oriented query language, and more
  • Exploit the optional and advanced Hibernate features to enhance your applications
  • Learn and integrate common Spring features that are a part and parcel of every Java project
  • Make the most out of the Spring features that are related to persistence, particularly to Hibernate
  • Develop sophisticated web applications using Spring Persistence with Hibernate and successfully test them

Here is a brief summary of what each chapter covers:

Chapter 1An Introduction to Hibernate and Spring introduces Spring and Hibernate, explaining what persistence is, why it is important, and how it is implemented in Java applications. It provides a theoretical discussion of Hibernate and how Hibernate solves problems related to persistence. Finally, we take a look at Spring and the role of Spring in persistence.

Chapter 2 - Preparing an Application to Use Spring with Hibernate guides you, step by step, down the path of preparing your application to use Hibernate and Spring. The prerequisites to developing with Hibernate and Spring—getting Hibernate and Spring distributions, setting up a database, and adding extra toolsand frameworks to your application—are all discussed here. 

Chapter 3 - A Quick Tour of Hibernate with Spring provides a quick tour of developing with Hibernate and Spring. Here, a simple example illustrates the basic concepts behind Hibernate and Spring.

Chapter 4Hibernate Configuration shows you how to configure and set up Hibernate. It discusses the basic configuration settings that are always required in any application. (Some optional settings are covered in the book's appendix.)

Chapter 5Hibernate Mappings explains basic issues related to persistent objects and their mappings. It starts with basic mapping concepts and then moves on to advanced and practical issues.

Chapter 6More on Mappings continues the mapping discussion with some advanced mapping topics. It explains how to map complex objects and create complicated mapping files.

Chapter 7Hibernate Types discusses how Hibernate types help to define which Java types are mapped to which SQL database types. It explores the built-in Hibernate types. It also looks at custom type implementation when these built-in types do not satisfy the application's requirements or when you want to change the default behavior of a built-in type.

Chapter 8 - Hibernate Persistence Behavior discusses the life cycle of persistent objects within the application's lifetime. This chapter explains the basic persistence operations provided by the Session API at the heart of the Hibernate API. The chapter also discusses how persistence operations are cascaded between persistent objects and how cascading behavior is defined in mapping files

Chapter 9Querying in Hibernate explains the different approaches that Hibernate provides for querying persistent objects. It investigates HQL, a Hibernate-specific query language; native SQL, a database-relevant query language; and the Criteria API, a Hibernate API to express query statements.

Chapter 10Inversion of Control with Spring starts developing with Spring, introducing the Inversion of Control (IoC) pattern that is implemented at the heart of Spring.

Chapter 11Spring AOP investigates Aspect-Oriented Programming (AOP) as another Spring feature. Here, you'll learn what AOP means, how AOP simplifies application architecture, and how to implement AOP in Spring.

Chapter 12 - Transaction Management discusses transaction management. It explains transaction concepts and how transactions are managed in native and Spring-based Hibernate applications. It also discusses caching as a persistence aspect that involves reliability of data manipulation.

Chapter 13 - Integrating Hibernate with Spring explains how Hibernate and Spring are integrated and introduces the Data Access Object (DAO) pattern. It shows how Spring and Hibernate combine to implement this pattern.

Chapter 14 - Web Development with Hibernate and Spring provides a quick discussion of web development with Spring and Hibernate. It does not provide a detailed discussion of web development; instead, it takes Spring and Struts as sample web frameworks to illustrate how you might use Spring and Hibernate to develop web applications.

Chapter 15Unit Testing looks into testing persistence code, with a focus on unit testing. It introduces JUnit as an open-source unit-testing framework and discusses which aspects of persistence code with Hibernate require testing.

Appendix - Hibernate's Advanced Features looks at some advanced Hibernate topics, including some useful Hibernate properties, the event/listener model implemented by Hibernate, and Hibernate filters.

In Detail

Spring is the leading platform to build and run enterprise Java applications. Spring's Hibernate integration makes it easy to mix and match persistence methodologies simplifying your Hibernate applications. You can incorporate lots of Inversion of Control (IoC) convenience features to address many typical Hibernate integration issues, making this integration all the more favorable for your application.

This easy-to-use book will turn the complex-sounding integration into a straightforward walk-through. Persistence is important for creating a data access-based transactions tier, central to financial, insurance, and banking applications. You will be able to enhance your applications using the most common, advanced, and optional features of Hibernate.

This book starts with the philosophy and the brief history of persistence. It provides an introduction to how persistence frameworks and technologies came into the development scene and what problems they are aimed to solve.

The book continues with a discussion about Hibernate as the most popular persistence framework in Java. First, you will learn how to get Hibernate and add it to a project and how to configure it before it can be used. Next, you will get an in-depth knowledge about Hibernate and understand the essential concepts behind persistence with Hibernate and more. When Hibernate has been fully discussed, you will get to know Spring as another popular framework in Java, and have a look at essential features of Spring and its added value for Hibernate-based projects. Finally the book will provide a comprehensive discussion about using Hibernate with Spring and the problems that are solved with Spring.

Authors

Table of Contents

Chapter 1: An Introduction to Hibernate and Spring
Persistence management in Java
Object relational mapping
Hibernate as an O/R Mapping solution
Hibernate architecture
What is Spring
Summary
Chapter 2: Preparing an Application to Use Spring with Hibernate
Setting up the database
Getting a Hibernate distribution
Getting a Spring distribution
Setting up the project hierarchy
Setting up Ant or Maven in the project
Summary
Chapter 3: A Quick Tour of Hibernate and Spring
Getting started with Hibernate
Hibernate declarative configuration
Some issues in mapping
Getting started with Spring
Hibernate with Spring
Summary
Chapter 4: Hibernate Configuration
Basic configuration information
Hibernate dialect
Configuring Hibernate
Using a single instance of SessionFactory
JPA configuration
Summary
Chapter 5: Hibernate Mappings
Persistent entity classes
Object/relational mapping metadata
Mapping inheritance hierarchy
Summary
Chapter 6: More on Mappings
Mapping components
Mapping collections
Mapping object associations
Summary
Chapter 7: Hibernate Types
Built-in types
Custom types
Summary
Chapter 8: Hibernate Persistence Behavior
The life cycle of persistent objects
Persistence with Hibernate
Cascading operations
Lazy loading
Some useful Session methods
Summary
Chapter 9: Querying In Hibernate
The Session API and querying
HQL
Bulk updates and bulk deletes with HQL
Queries in native SQL
Named SQL and HQL queries
Using the Criteria API
Paging the query result
Logging the Hibernate-Generated SQL
Summary
Chapter 10: Inversion of Control with Spring
Inversion of Control and dependency injection
Inversion of Control in Spring
Applying IoC to Hibernate resources
PropertyEditors
Summary
Chapter 11: Spring AOP
Introduction to AOP
Using Spring AOP with Spring IoC: An example
Spring's AOP framework
Moving to Spring 2.x's AOP
Summary
Chapter 12: Transaction Management
Transaction essentials
Transactions in Hibernate applications
Spring transaction abstraction
Caching
Summary
Chapter 13: Integrating Hibernate with Spring
The Data Access Object pattern
Service Facade Pattern
Data tier implementation with Hibernate
Data tier implementation with Spring
Spring exception translation
Refactoring DAO classes to use Spring
Configuring Hibernate in a Spring context
Spring transaction management
Summary
Chapter 14: Web Development with Hibernate and Spring
Problem definition
The MVC architectural pattern
Spring MVC web framework
Summary
Chapter 15: Testing
An introduction to unit testing
Unit testing with JUnit
Integration testing data-access layer
Testing Inversion of Control
Unit testing using mocks
Automating tests with Ant
Summary

Book Details

ISBN 139781849510561
Paperback460 pages
Read More