SpringDataJPA-Spring entry study notes 08

The content of the course comes from the geek time playing Spring Family Bucket, the link is as follows
https://time.geekbang.org/course/intro/100023501

Fifth day and a half

SpringDataJPA concept

Why does OR Mapping exist?

The following table shows the relationship between Object and RDBMS.
Insert picture description here
With such a mismatch, there is a framework for object-relational mapping between Hibernate and JDO.

In 2006, 3.2 Hibernate became the implementation of JPA and was released as part of JSR 220

JPA stands for Java Persistence API, which provides a POJO-based persistence model for object-relational mapping

  • Simplify the development of data persistence code
  • Shield the differences of different persistence APIs for the Java community (shield JDO, EJB, etc.)

JPA was supported in the early Spring, and it was later taken out separately into Spring Data, which was the same Spring Data module as Spring Data Common, Spring Data JDBC, etc.

Define JPA entity objects

Use annotations to define entities:
JPA annotations
entities

  • @Entity defines the class as an entity
  • @MappedSuperclass The parent class of multiple entity classes
  • @Table(name) The entity is associated with the corresponding table

Primary key

  • @Id primary key
  • @GeneratedValue(strategy, generator) Generation strategy: self-increasing order class, generator, etc.
  • @SequenceGenerator(name, sequenceName) Generate sequence

Mapping

  • @Column(name, nullable, length, insertable, updatable) defines the mapping relationship between attributes and fields in the table. Generally, the attribute name is the name of the corresponding field; you can also specify the name in name
  • @JoinTable(name), @JoinColumn(name) are used when linking

relationship

  • @OneToOne、@OneToMany、@ManyToOne、@ManyToMany
  • @OrderBy sort

Lombok

Project Lombok can automatically embed IDE and build tools to improve development efficiency

  • @Getter / @Setter
  • @ToString
  • @NoArgsConstructor / @RequiredArgsConstructor / @AllArgsConstructor
  • @Data is equivalent to Getter / Setter + ToString
  • @Builder
  • @Slf4j / @CommonsLog / @Log

JPA implementation logic

How is Repository Bean created

JpaRepositoriesRegistrar
activated @EnableJpaRepositories and
returned JpaRepositoryConfigExtensio

RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions
registered Repository Bean (type is JpaRepositoryFactoryBean)

RepositoryConfigurationExtensionSupport.getRepositoryConfigurations
取得 Repository 配置

JpaRepositoryFactory.getTargetRepository
created the Repository

How are the methods in the interface interpreted

RepositoryFactorySupport.getRepository 了 了 Advice
DefaultMethodInvokingMethodInterceptor
QueryExecutorMethodInterceptor

AbstractJpaQuery.execute executes specific queries

Guess you like

Origin blog.csdn.net/weixin_43596589/article/details/112604771