Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
177 views

SpringBoot Basics

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views

SpringBoot Basics

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Application Properties

Spring Boot Framework comes with a built-in mechanism for application configuration
using a file called application.properties.
The application.properties file allows us to run an application in a different
environment.

○ Configure the Spring Boot framework

○ define our application custom configuration properties

Spring Boot Property Categories


There are 16 Application Properties

1. Core Properties

2. Cache Properties

3. Mail Properties

4. JSON Properties

5. Data Properties

6. Transaction Properties

7. Data Migration Properties

8. Integration Properties

9. Web Properties

10. Templating Properties

11. Server Properties

12. Security Properties

13. RSocket Properties

14. Actuator Properties

15. DevTools Properties

16. Testing Properties


SPRING BOOT JPA

Spring Boot JPA is a Java specification for managing relational data in Java
applications. It allows us to access and persist data between Java object/ class
and relational database. JPA follows Object-Relation Mapping (ORM). It is a set
of interfaces. It also provides a runtime EntityManager API for processing
queries and transactions on the objects against the database. It uses a
platform-independent object-oriented query language JPQL (Java Persistent
Query Language).

○ The Java Persistence API

○ Object-Relational metadata

○ The API itself, defined in the persistence package

JPA is not a framework. It defines a concept that can be implemented by any


framework.

Why should we use JPA?

JPA is simpler, cleaner, and less labor-intensive than JDBC, SQL, and hand-written
mapping. JPA is suitable for non-performance oriented complex applications. The
main advantage of JPA over JDBC is that, in JPA, data is represented by objects and
classes while in JDBC data is represented by tables and records. It uses POJO to
represent persistent data that simplifies database programming. There are some other
advantages of JPA.
JPA is an open-source API. There is various enterprises vendor such as Eclipse,
RedHat, Oracle, etc. that provides new products by adding the JPA in them. There are
some popular JPA implementations frameworks such as Hibernate, EclipseLink,
DataNucleus, etc. It is also known as Object-Relation Mapping (ORM) tool.

Object-Relation Mapping (ORM)

In ORM, the mapping of Java objects to database tables, and vice-versa is called
Object-Relational Mapping. The ORM mapping works as a bridge between a relational
database (tables and records) and Java application (classes and objects).

○ JPA avoids writing DDL in a database-specific dialect of SQL. Instead of this, it


allows mapping in XML or using Java annotations.

○ JPA allows us to avoid writing DML in the database-specific dialect of SQL.

○ JPA allows us to save and load Java objects and graphs without any DML
language at all.

○ When we need to perform queries JPQL, it allows us to express the queries in


terms of Java entities rather than the (native) SQL table and columns.

JPA Features

There are following features of JPA:

○ It is a powerful repository and custom object-mapping abstraction.

○ It supports for cross-store persistence. It means an entity can be partially


stored in MySQL and Neo4j (Graph Database Management System).

○ It dynamically generates queries from queries methods name.

○ The domain base classes provide basic properties.

○ It supports transparent auditing.


○ Possibility to integrate custom repository code.

○ It is easy to integrate with Spring Framework with the custom namespace.

JPA Architecture

JPA is a source to store business entities as relational entities. It shows how to define
a POJO as an entity and how to manage entities with relation.

The following figure describes the class-level architecture of JPA that describes the
core classes and interfaces of JPA that is defined in the javax persistence package.
The JPA architecture contains the following units:

○ Persistence: It is a class that contains static methods to obtain an


EntityManagerFactory instance.

○ EntityManagerFactory: It is a factory class of EntityManager. It creates and


manages multiple instances of EntityManager.

○ EntityManager: It is an interface. It controls the persistence operations on


objects. It works for the Query instance.

○ Entity: The entities are the persistence objects stores as a record in the
database.

○ Persistence Unit: It defines a set of all entity classes. In an application,


EntityManager instances manage it. The set of entity classes represents the
data contained within a single data store.

○ EntityTransaction: It has a one-to-one relationship with the EntityManager


class. For each EntityManager, operations are maintained by EntityTransaction
class.

○ Query: It is an interface that is implemented by each JPA vendor to obtain


relation objects that meet the criteria.
JPA Class Relationships

The classes and interfaces that we have discussed above maintain a relationship. The
following figure shows the relationship between classes and interfaces.
○ The relationship between EntityManager and EntiyTransaction is one-to-one.
There is an EntityTransaction instance for each EntityManager operation.

○ The relationship between EntityManageFactory and EntiyManager is one-to-


many. It is a factory class to EntityManager instance.

○ The relationship between EntityManager and Query is one-to-many. We can


execute any number of queries by using an instance of EntityManager class.

○ The relationship between EntityManager and Entity is one-to-many. An


EntityManager instance can manage multiple Entities.

JPA Implementations

JPA is an open-source API. There is various enterprises vendor such as Eclipse,


RedHat, Oracle, etc. that provides new products by adding the JPA in them. There are
some popular JPA implementations frameworks such as Hibernate, EclipseLink,
DataNucleus, etc. It is also known as Object-Relation Mapping (ORM) tool.

Object-Relation Mapping (ORM)

In ORM, the mapping of Java objects to database tables, and vice-versa is called
Object-Relational Mapping. The ORM mapping works as a bridge between a relational
database (tables and records) and Java application (classes and objects).

In the following figure, the ORM layer is an adapter layer. It adapts the language of
object graphs to the language of SQL and relation tables.
The ORM layer exists between the application and the database. It converts the Java
classes and objects so that they can be stored and managed in a relational database.
By default, the name that persists become the name of the table, and fields become
columns. Once an application sets-up, each table row corresponds to an object.

In 2019, JPA renamed to Jakarta Persistence. The latest version of JPA is 2.2. It
supports the following features:

○ Java 8, data and time API


○ CDI Injection in AttributeConvertes

○ It makes annotations @Repeatable

JPA: JPA is a Java specification that is used to access, manage, and persist data
between Java object and relational database. It is a standard approach for ORM.

Hibernate: It is a lightweight, open-source ORM tool that is used to store Java objects in
the relational database system. It is a provider of JPA. It follows a common approach
provided by JPA.

MVC
A Spring MVC is a Java framework which is used to build web applications. It follows
the Model-View-Controller design pattern. It implements all the basic features of a core
spring framework like Inversion of Control, Dependency Injection.

○ Model - A model contains the data of the application. A data can be a single
object or a collection of objects.

○ Controller - A controller contains the business logic of an application. Here, the


@Controller annotation is used to mark the class as the controller.

○ View - A view represents the provided information in a particular format.


Generally, JSP+JSTL is used to create a view page. Although spring also
supports other view technologies such as Apache Velocity, Thymeleaf and
FreeMarker.

○ Front Controller - In Spring Web MVC, the DispatcherServlet class works as the
front controller. It is responsible to manage the flow of the Spring MVC
application.

You might also like