Chapter 3

  1. Object-relational mapping (ORM) is a technique that allows you to fetch and manipulate data from a database using an object-oriented programming paradigm. Java Persistence API (JPA) provides object-relational mapping for Java developers. Hibernate is a Java-based JPA implementation.
  2. The entity class is just a standard Java class that is annotated with the @Entity annotation. You have to implement constructors, fields, getters, and setters inside the class. The unique ID field(s) are annotated with the @Id annotation. 
  3. You have to create a new interface that extends the Spring Data CrudRepository interface. You define the entity and the type of the id field in the type arguments—for example, <Car, Long>.
  4. CrudRepository provides all CRUD operations to your entity. You can create, read, update, and delete your entities using CrudRepository.
  5. You have to create entity classes and link the entities using the @OneToMany and @ManyToOne annotations.
  6. You can add demo data to your main application class using CommandLineRunner.
  7. Define the endpoint for the H2 console in your application.properties file and enable it. Then, you can access the H2 console by navigating to the defined endpoint with a web browser.
  8. You have to add the MariaDB dependency to the pom.xml file and define the database connection settings in the application.properties file. Remove the H2 database dependency from the pom.xml file if you have used that.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.240.178