Spring Persistence Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:
=Repository=
=Repository=


A repository is a Data Access Layer (or Persistence Layer) application component that intermediates interaction with a database: all database-related operations are done though the repository. The repository object conceals all low-level operations that are required by the interaction with the database and exposes to the application only high level operations such as "find", "save", etc., all these taking domain model object instance arguments.
A repository is a Data Access Layer (or Persistence Layer) application component that intermediates interaction with a database: all database-related operations are done though the repository. The repository object conceals all low-level operations that are required by the interaction with the database and exposes to the application only high level operations such as queries, save, etc., all these taking domain model object instance arguments.


Any repository implementation needs access to a persistence resource, depending on the persistence technology used. For example, a JDBC-based repository needs access to a [[DataSource#Overview|JDBC DataSource]], while a JPA-based repository needs access to an [[JPA Concepts#EntityManager|EntityManager]]. A repository can be configured with XML, or the corresponding Java class can be annotated with the [[@Repository]] [[Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#Stereotype|stereotype annotation]].
Any repository implementation needs access to a persistence resource, depending on the persistence technology used. For example, a JDBC-based repository needs access to a [[DataSource#Overview|JDBC DataSource]], while a JPA-based repository needs access to an [[JPA Concepts#EntityManager|EntityManager]]. A repository can be configured with XML, or the corresponding Java class can be annotated with the [[@Repository]] [[Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#Stereotype|stereotype annotation]].

Revision as of 20:49, 14 October 2018

Internal

Overview

DAO

Repository

A repository is a Data Access Layer (or Persistence Layer) application component that intermediates interaction with a database: all database-related operations are done though the repository. The repository object conceals all low-level operations that are required by the interaction with the database and exposes to the application only high level operations such as queries, save, etc., all these taking domain model object instance arguments.

Any repository implementation needs access to a persistence resource, depending on the persistence technology used. For example, a JDBC-based repository needs access to a JDBC DataSource, while a JPA-based repository needs access to an EntityManager. A repository can be configured with XML, or the corresponding Java class can be annotated with the @Repository stereotype annotation.

Object IDs

  • When persisting objects in a relational database, it is generally a good idea to have one field in the object that uniquely identifies the object. See Relational Databases.