Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Full Stack Development with Spring Boot 2.0 and React

You're reading from  Hands-On Full Stack Development with Spring Boot 2.0 and React

Product type Book
Published in Jun 2018
Publisher Packt
ISBN-13 9781789138085
Pages 302 pages
Edition 1st Edition
Languages
Author (1):
Juha Hinkula Juha Hinkula
Profile icon Juha Hinkula

Table of Contents (24) Chapters

Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
1. Setting Up the Environment and Tools – Backend 2. Using JPA to Create and Access a Database 3. Creating a RESTful Web Service with Spring Boot 4. Securing and Testing Your Backend 5. Setting Up the Environment and Tools – Frontend 6. Getting Started with React 7. Consuming the REST API with React 8. Useful Third-Party Components for React 9. Setting Up the Frontend for Our Spring Boot RESTful Web Service 10. Adding CRUD Functionalities 11. Styling the Frontend with React Material-UI 12. Testing Your Frontend 13. Securing Your Application 14. Deploying Your Application 15. Best Practices 1. Assessments 2. Other Books You May Enjoy Index

Chapter 2. Using JPA to Create and Access a Database

This chapter covers how to use JPA with Spring Boot. We will create a database by using entity classes. In the first phase, we will be using the H2 in-memory database for development and demonstration purposes. H2 is an in-memory SQL database that is really good for fast development or demonstration purposes. In the second phase, we will move from H2 to use MariaDB. This chapter also describes the creation of CRUD repositories and a one-to-many connection between database tables.

In this chapter, we will look at the following:

  • Basics and benefits of using JPA
  • How to define a database by using entity classes
  • How to create Spring Boot backend with a database

Technical requirements


Java SDK version 8 or higher is necessary for the usage of Spring Boot (http://www.oracle.com/technetwork/java/javase/downloads/index.html).

A MariaDB installation is necessary for the creation of the database application (https://downloads.mariadb.org/).

Basics of ORM, JPA, and Hibernate

Object-Relational Mapping (ORM) is a technique that allows you to fetch and manipulate from a database by using an object-oriented programming paradigm. ORM is really nice for programmers because it relies on object-oriented concepts, not on database structure. It also makes development much faster and reduces the amount of source code. ORM is mostly independent of the databases and developers don't have to worry about vendor-specific SQL statements.

Java Persistent API (JPA) provides object-relational mapping for Java developers. The JPA entity is a Java class that presents the structure of a database table. The fields of an entity class present the columns of the database tables.

Hibernate...

Summary


In this chapter, we used JPA to create our Spring Boot application database. First, we created entity classes, which are mapped to database tables. Then, we created CrudRepository for our entity class and that provides CRUD operations for the entity. After that, we managed to add some demo data to our database by using CommandLineRunner. We also created one-to-many relations between two entities. At the beginning of the chapter, we used the H2 in-memory database, while at the end, we switched the database to MariaDB. In the next chapter we will create RESTful web service to our backend.

Questions


  1. What are ORM, JPA, and Hibernate?
  2. How can you create an entity class?
  3. How can you create CrudRepository?
  4. How does the CrudRepository provide for your application?
  5. How can you create a one-to-many relationship between tables?
  6. How can you add demo data to a database with Spring Boot?
  7. How can you access the H2 console?
  8. How can you connect your Spring Boot application to MariaDB?
lock icon The rest of the chapter is locked
You have been reading a chapter from
Hands-On Full Stack Development with Spring Boot 2.0 and React
Published in: Jun 2018 Publisher: Packt ISBN-13: 9781789138085
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}