springdata-jpa multiple data source configuration

Project structure 1. Dependence <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.18</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!– MySQL driver, note, this needs to correspond to the MySQL version –> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.31</version> <scope>runtime</scope> </dependency> <!–web–> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!–fastjson–> <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>2.0.4</version> </dependency> </dependencies> 2.application.yml server: port: 8900 #Port […]

11 | How to customize JpaRepository

EntityManager introduction The Java Persistence API stipulates that operating database entities must be performed through EntityManager. As we saw earlier, the implementation class of all Repositories in JPA is SimpleJpaRepository, which calls methods in EntityManager when it actually operates entities. We set a breakpoint in SimpleJpaRepository, so that we can easily see that EntityManger is […]

12 | What problems does JPA’s auditing function solve?

What does Auditing mean? Auditing is used for auditing. When we operate a record, we need to know who created it, when it was created, who last modified it, when was the last modification time, and even the record needs to be modified… these They are all supported by Auditing in Spring Data JPA. It […]

09 | What problems does JpaSpecificationExecutor solve?

QueryByExampleExecutor usage QueryByExampleExecutor (QBE) is a user-friendly query technology with a simple interface that allows dynamic query creation and eliminates the need to write queries containing field names. The following is a UML diagram. You can see that QueryByExampleExecutor is the parent interface of JpaRepository, that is, JpaRespository inherits all methods of QueryByExampleExecutor. Figure 1: […]

java.util.NoSuchElementException problem (about exceptions thrown by using @ApiModelProperty annotation to map field annotations in JPA self-built tables)

When I was doing the one-to-many (many-to-one) relationship mapping of SpringDateJPA, I wanted Jpa to automatically add annotations when creating the table, so Baidu came up with two methods: one is to use the columnDefinition attribute in the @Column annotation for override Statements in database DDL: @Column(columnDefinition = “varchar DEFAULT NULL COMMENT ‘Type'”) private String […]

[spring data jpa] ID generation strategy (GeneratedValue)

1. Add dependencies Add spring data jpa dependency in pom file <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>3.1.4</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>6.3.1.Final</version> </dependency> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <version>10.14.2.0</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.1</version> <scope>test</scope> </dependency> The 3.1.4 version of spring data jpa is used here, and hibernate, derby, junit and other packages are also introduced. 2. Create […]

[spring] spring jpa-hibernate CRUD

[spring] spring jpa – hibernate CRUD Previous Notes [spring] spring jpa – hibernate terminology & configuration After passing through some conceptual things, this note will go through the practical operations CRUD This is implemented through EntityManager (Spring’s dependency injected through DI) and DAO (design pattern). The general implementation structure is to generate a DAO interface, […]

Automatically generate simple tools for JPA beans and repository generation

Because the tool is not very flexible, I wrote one by hand. It is not technically difficult and only requires a lot of code. import java.io.File; import java.io.FileOutputStream; import java.nio.charset.Charset; import java.sql.*; import java.util.*; /** * JPA dao automatic generation tool */ public class JpaGenerate { //The location of the bean, example: com.jpa.bean static String […]