Almost every application needs to access data. In this course, you will learn about Spring support for data access from relational databases.
This course covers:
- Understanding data access in Spring
- Implementing Spring"s JDBC Template support
- Performing read and write operations
- Integrating with the Hibernate ORM framework
UNIT
Spring Data’s mission is to provide a familiar and consistent, Spring-based programming model for data access while still retaining the special traits of the underlying data store.
It makes it easy to use data access technologies, relational and non-relational databases, map-reduce frameworks, and cloud-based data services. This is an umbrella project which contains many subprojects that are specific to a given database.
Its main modules are:
Spring Data Commons - Core Spring concepts underpinning every Spring Data module.
Spring Data JDBC - Spring Data repository support for JDBC.
Spring Data JDBC Ext - Support for database specific extensions to standard JDBC including support for Oracle RAC fast connection failover, AQ JMS support and support for using advanced data types.
Spring Data JPA - Spring Data repository support for JPA.
Spring Data KeyValue - Map based repositories and SPIs to easily build a Spring Data module for key-value stores.
Spring Data LDAP - Spring Data repository support for Spring LDAP.
Spring Data MongoDB - Spring based, object-document support and repositories for MongoDB.
Spring Data Redis - Easy configuration and access to Redis from Spring applications.
Spring Data REST - Exports Spring Data repositories as hypermedia-driven RESTful resources.
Spring Data for Apache Cassandra - Easy configuration and access to Apache Cassandra or large scale, highly available, data oriented Spring applications.
Spring Data for Apace Geode - Easy configuration and access to Apache Geode for highly consistent, low latency, data oriented Spring applications.
Spring Data for Apache Solr - Easy configuration and access to Apache Solr for your search oriented Spring applications.
Spring Data for Pivotal GemFire - Easy configuration and access to Pivotal GemFire for your highly consistent, low latency/high through-put, data oriented Spring applications.
This unit introduces you to Spring Data's JDBC support and makes the case for it by contrasting it with just plain JDBC. Learn how Spring's data integration removes the boilerplate code you'd typically have to write.
This tutorial serves as an introduction to Spring Data support. We'll also install a lightweight database Apache Derby that we'll use in subsequent tutorials. We'll learn how to start Derby in Network server mode, and how to connect and run SQL queries using the ij client tool.
We'll now implement a simple DAO class that fetches data from the database using JDBC. We'll look at all the boilerplate code we need to write to establish connections, execute queries, close objects and handle exceptions.
UNIT
Learn about the various support classes provided by Spring for the purpose of data integration. Connect with database using JDBC and Hibernate using Spring's template classes.
We'll now add the Spring framework to our JDBC project. We'll add dependency injection to our Main and DAO class. We'll also learn how to configure DataSource as a Spring bean and supply connection parameters to it in the XML file.
We'll use the JdbcTemplate class provided by Spring to implement a DAO method. We'll see how using the template class makes the DAO methods simple, and how it takes care of much of the boilerplate code we'd have to write otherwise.
We returned an integer datatype result from our query in the previous tutorial. In this tutorial, we'll learn how to return other datatypes. We'll implement a method that returns a String query output.
In this tutorial, we implement a custom RowMapper class to map our domain objects. We then use this class to write fetch methods that return custom model objects.
We'll now implement some database write operations. We'll write a DAO method to update a value in the database, as well as use the execute() method to run a DDL SQL query.
We'll use the NamedParameterJdbcTemplate class to run queries with named placeholders.
We'll wrap up discussion on the Spring JDBC support by using the DAO support classes that Spring provides out of the box. We'll see how this makes our DAO classes cleaner than ever.
In this video, we'll learn how to integrate the Hibernate framework in our Spring application. We'll create a SessionFactory as a Spring singleton and use that in our DAO class to work with the database.
JPA or Java Persistence API is a standard specification for ORM implementations whereas Hibernate is the actual ORM implementation or framework. JPA is Java Persistence API. ... Hibernate is a JPA provider/Vendor who responsible for implementing that APIs.
DAO is an abstraction of data persistence. Repository is an abstraction of a collection of objects.
DAO would be considered closer to the database, often table-centric. Repository would be considered closer to the Domain, dealing only in Aggregate Roots. A Repository could be implemented using DAO's, but you wouldn't do the opposite.
Also, a Repository is generally a narrower interface. It should be simply a collection of objects, with a Get(id), Find(ISpecification), Add(Entity). A method like Update is appropriate on a DAO, but not a Repository - when using a Repository, changes to entities would usually be tracked by separate UnitOfWork.
In this Spring project, we annotate DAO classes with @Repository too. :-(
DAO is a class that usually has the CRUD operations like save, update, delete. Whereas the DTO is just an object that holds data. It is really a glorified JavaBean with instance variables and setter and getters. Usually it is the DTO that is passed to the save method of a DAO