Data Access Layer

JPA Entity

  • The Java Persistence API (JPA), part of the Java Enterprise.
  • Provides an object-relational mapping approach that lets you declaratively define how to map Java objects to relational database tables in a standard.
  • Entities represent persistent data stored in a relational database automatically using container-managed persistence.
  • They are persistent because their data is stored persistently in some form of data storage system, such as a database: they do survive a server failure, failover, or a network failure.

POJO

ORM

  • Object-Relational Mapping or ORM is a technique for converting data between Java objects and relational databases.
  • ORM converts data between two incompatible type systems (Java and MySQL), such that each model class becomes a table in our database and each instance a row of the table.

Data Layer architecture

  • The data tier provides functionality to access and manage data. The data tier contains a data store for persistent storage, such as an RDBMS. It provides services and data for the business tier.
  • There are variations of n-tier architectures that go beyond just three tiers. For example, in some systems, there is a data access or persistence layer in addition to a data or database layer.
  • The persistence layer contains components for data access, such as an object-relational mapping (ORM) tool, and the database layer includes the actual data store, such as an RDBMS. One reason to separate these into two distinct layers is if you wanted the ability to switch out your data access or database technology for a different one.
Figure of Data Access Layer

ORM

  • Object-relational-mapping is the idea of being able to write queries like the one above, as well as much more complicated ones, using the object-oriented paradigm of your preferred programming language.
  • Long story short, we are trying to interact with our database using our language of choice instead of SQL.

Characteristics:

  • Simplified development because it automates object-to-table and table-to-object conversion, resulting in lower development and maintenance costs.
  • Less code compared to embedded SQL and handwritten stored procedures Transparent object caching in the application tier, improving system performance An optimized solution making an application faster and easier to maintain.
  • ORM’s emergence in multiple application development has created disagreement among experts. Key concerns are that ORM does not perform well and that stored procedures might be a better solution. In addition, ORM dependence may result in poorly-designed databases in certain circumstances.

Examples:

Entity relationship with JPA

Example Data Layer

External Resources