DB with Spring boot

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.


要查看或添加评论,请登录

Saurabh Gadekar的更多文章

  • Basic Authentication and JWT with Springboot

    Basic Authentication and JWT with Springboot

    Authentication and Authorization Authentication is the process of verifying who is user, while authorization is the…

  • Multithreading in Java

    Multithreading in Java

    process: Any active execution thread: thread is lightweight sub process. using two ways we can implement: 1) Runnable…

  • Service Discovery in Microservices

    Service Discovery in Microservices

    Service Discovery is the automatic detection of devices and services offered by these devices on a computer network. In…

  • Autowiring with @Qualifier and @Primary Annotations in Springboot

    Autowiring with @Qualifier and @Primary Annotations in Springboot

    @Autowired is a mechanism by which Spring Boot automatically resolves and injects collaborating beans into your…

  • Scheduling in Springboot

    Scheduling in Springboot

    Job scheduling is a crucial aspect of many applications, especially when it comes to automating repetitive tasks…

  • Logging in Springboot

    Logging in Springboot

    In spring boot application logging plays important role to keep track on all the actions, activities and events…

  • Rest Template

    Rest Template

    RestTemplate is a powerful synchronous client for handling HTTP communication in Spring Boot applications. Internally…

  • Fault tolerance in Microservices

    Fault tolerance in Microservices

    Preventing system from temporary or permanent failure is the purpose of fault tolerance. In microservices environment…

  • Caching with Springboot

    Caching with Springboot

    Caching is a part of temporary memory. It lies between the application and persistence database.

  • Actuator

    Actuator

    Dependency required: org.springframework.

社区洞察

其他会员也浏览了