Chapter 4. Querying a Database

In this chapter, we will cover the following recipes:

  • Connecting to a database
  • Creating a DAO class
  • Calling a DAO method from a controller class
  • Saving an object
  • Retrieving an object
  • Retrieving a list of objects
  • Retrieving a list of objects with their dependencies
  • Updating an object
  • Deleting an object
  • Finding the number of results for an SQL query
  • Saving a list of objects at once
  • Reverting incomplete database modifications using transactions
  • Using Hibernate for powerful object persistence and querying

Introduction

JDBC (Java Database Connectivity) and Hibernate are the two most commonly used technologies to query a database from a Spring application.

For small projects and simple data models, JDBC is straightforward; you write your ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.