DB with Spring boot
*Configuration for connecting db to springboot application
-need to configure application.yml file
inside application file need to provide data for few fields
1) spring.datasource.url
2) spring.datasource.username
3) spring.datasource.password
4) spring.datasource.driver-class-name
JPA (Java Persistence API)
Requirements: application should be running above java 8+
Annotation which helps jpa to understand about fields:?
Model layer
@Entity: This annotation defines that a class can be mapped to a table
@Id: This annotation specifies the primary key of the entity.
@GeneratedValue: This annotation is used to specify the primary key generation strategy to use. i.e. Instructs database to generate a value for this field automatically. If the strategy is not specified by default AUTO will be used.
Repository layer
@Repository
Important annotation
@Transient: Tells the hibernate, not to add this particular column
What is JPA?
A JPA (Java Persistence API) is a specification of Java which is used to access, manage, and persist data between Java object and relational database. It is considered as a standard approach for Object Relational Mapping.
JPA can be seen as a bridge between object-oriented domain models and relational database systems. Being a specification, JPA doesn't perform any operation by itself. Thus, it requires implementation. So, ORM tools like Hibernate, TopLink, and iBatis implements JPA specifications for data persistence.
What is Hibernate?
A Hibernate is a Java framework which is used to store the Java objects in the relational database system. It is an open-source, lightweight, ORM (Object Relational Mapping) tool.
Hibernate is an implementation of JPA. So, it follows the common standards provided by the JPA.