Merge branch 'eugenp:master' into master
This commit is contained in:
@@ -87,7 +87,7 @@
|
||||
<oracle.driver.version>10.2.0.4.0</oracle.driver.version>
|
||||
<mysql.driver.version>8.2.0</mysql.driver.version>
|
||||
<jooq.version>3.11.11</jooq.version>
|
||||
<json.version>20220320</json.version>
|
||||
<json.version>20240303</json.version>
|
||||
<microstream.storage.version>07.00.00-MS-GA</microstream.storage.version>
|
||||
<h2.version>2.1.214</h2.version>
|
||||
<spring-jdbc.version>5.3.29</spring-jdbc.version>
|
||||
|
||||
+159
-74
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
||||
CREATE TRIGGER IF NOT EXISTS TGR_UpdatePersonName AFTER INSERT
|
||||
ON Person FOR EACH ROW UPDATE PERSON SET NAME = 'Neymar Santos' where NAME = 'Zeeshan Arif'
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -4,13 +4,9 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>liquibase</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<name>liquibase</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>persistence-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -18,6 +14,38 @@
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>${mysql-connector-java.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<version>${liquibase.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${postgresql.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.lbruun.springboot</groupId>
|
||||
<artifactId>preliquibase-spring-boot-starter</artifactId>
|
||||
<version>${preliquibase.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -32,12 +60,30 @@
|
||||
<changeLogFile>liquibase/db-changelog.xml</changeLogFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<release>${maven.compiler.release}</release>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<source>${maven.compiler.source.version}</source>
|
||||
<target>${maven.compiler.target.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<mysql-connector-java.version>8.2.0</mysql-connector-java.version>
|
||||
<liquibase-maven-plugin.version>4.25.0</liquibase-maven-plugin.version>
|
||||
<maven.compiler.source.version>17</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>17</maven.compiler.target.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
<java.version>17</java.version>
|
||||
<spring-boot.version>3.2.3</spring-boot.version>
|
||||
<liquibase.version>4.26.0</liquibase.version>
|
||||
<postgresql.version>42.7.2</postgresql.version>
|
||||
<preliquibase.version>1.5.0</preliquibase.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.liquibase;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class LiquibaseCreateSchemaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LiquibaseCreateSchemaApplication.class, args);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.liquibase.configuration;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class SchemaInitializer implements BeanPostProcessor {
|
||||
|
||||
@Value("${spring.liquibase.default-schema}")
|
||||
private String schemaName;
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof DataSource) {
|
||||
DataSource dataSource = (DataSource) bean;
|
||||
try {
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement statement = conn.createStatement();
|
||||
statement.execute(String.format("CREATE SCHEMA IF NOT EXISTS %s", schemaName));
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.liquibase.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users")
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#spring.datasource.url=jdbc:postgresql://some-postgresql-host/some-postgresql-database
|
||||
#spring.datasource.username=your-postgresql-username
|
||||
#spring.datasource.password=your-postgresql-password
|
||||
#spring.liquibase.change-log=classpath:liquibase/changelog.xml
|
||||
#spring.liquibase.default-schema=user_management
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
|
||||
|
||||
<changeSet id="0" author="unknown">
|
||||
<sql>
|
||||
CREATE SCHEMA IF NOT EXISTS user_management;
|
||||
</sql>
|
||||
</changeSet>
|
||||
<changeSet id="1" author="unknown">
|
||||
<createTable tableName="users" schemaName="user_management">
|
||||
<column name="id" type="bigint">
|
||||
<constraints primaryKey="true" nullable="false"/>
|
||||
</column>
|
||||
<column name="name" type="varchar(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
|
||||
|
||||
<changeSet id="1" author="unknown">
|
||||
<createTable tableName="users">
|
||||
<column name="id" type="bigint">
|
||||
<constraints primaryKey="true" nullable="false"/>
|
||||
</column>
|
||||
<column name="name" type="varchar(255)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1 @@
|
||||
CREATE SCHEMA IF NOT EXISTS user_management;
|
||||
@@ -82,7 +82,6 @@
|
||||
<module>spring-data-jpa-annotations</module>
|
||||
<module>spring-data-jpa-annotations-2</module>
|
||||
<module>spring-data-jpa-crud</module>
|
||||
<module>spring-data-jpa-crud-2</module>
|
||||
<module>spring-data-jpa-enterprise</module>
|
||||
<module>spring-data-jpa-enterprise-2</module>
|
||||
<module>spring-data-jpa-filtering</module>
|
||||
@@ -93,6 +92,7 @@
|
||||
<module>spring-data-jpa-repo-2</module>
|
||||
<module>spring-data-jpa-repo-4</module>
|
||||
<module>spring-data-jdbc</module>
|
||||
<module>spring-data-jpa-simple</module>
|
||||
<module>spring-data-keyvalue</module>
|
||||
<module>spring-data-mongodb</module>
|
||||
<module>spring-data-mongodb-2</module>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
### Relevant Articles:
|
||||
- [Intro to Querydsl](https://www.baeldung.com/intro-to-querydsl)
|
||||
- [A Guide to Querydsl with JPA](https://www.baeldung.com/querydsl-with-jpa-tutorial)
|
||||
- [Querydsl vs. JPA Criteria](https://www.baeldung.com/jpa-criteria-querydsl-differences)
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.dependencies}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.dependencies}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
logging.level.org.hibernate:
|
||||
SQL: DEBUG
|
||||
type.descriptor.sql.BasicBinder: TRACE
|
||||
SQL: INFO
|
||||
type.descriptor.sql.BasicBinder: INFO
|
||||
@@ -7,4 +7,5 @@
|
||||
- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime)
|
||||
- [A Guide to @DBRef in MongoDB](https://www.baeldung.com/spring-mongodb-dbref-annotation)
|
||||
- [Import Data to MongoDB From JSON File Using Java](https://www.baeldung.com/java-import-json-mongodb)
|
||||
- [Spring Data MongoDB – Configure Connection](https://www.baeldung.com/spring-data-mongodb-connection)
|
||||
- More articles: [[next-->]](../spring-boot-persistence-mongodb-2)
|
||||
|
||||
+2
-1
@@ -10,4 +10,5 @@ spring.thymeleaf.cache=false
|
||||
|
||||
spring.servlet.multipart.max-file-size=256MB
|
||||
spring.servlet.multipart.max-request-size=256MB
|
||||
spring.servlet.multipart.enabled=true
|
||||
spring.servlet.multipart.enabled=true
|
||||
spring.data.mongodb.uri=mongodb://localhost
|
||||
+13
-12
@@ -2,30 +2,31 @@ package com.baeldung.mongodb;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.baeldung.mongodb.daos.UserRepository;
|
||||
import com.baeldung.mongodb.models.User;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@DirtiesContext
|
||||
public class MongoDbAutoGeneratedFieldIntegrationTest {
|
||||
@DataMongoTest
|
||||
class MongoDbAutoGeneratedFieldIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
UserRepository userRepository;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {}
|
||||
void contextLoads() {
|
||||
// Verifies the context is loaded correctly
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUserObject_whenSave_thenCreateNewUser() {
|
||||
void givenUserObject_whenSave_thenCreateNewUser() {
|
||||
|
||||
User user = new User();
|
||||
user.setFirstName("John");
|
||||
@@ -33,8 +34,8 @@ public class MongoDbAutoGeneratedFieldIntegrationTest {
|
||||
user.setEmail("[email protected]");
|
||||
userRepository.save(user);
|
||||
|
||||
assertThat(userRepository.findAll().size()).isGreaterThan(0);
|
||||
assertThat(userRepository.findAll()
|
||||
.size()).isPositive();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
## Spring Data JPA - CRUD
|
||||
|
||||
This module contains articles about CRUD operations in Spring Data JPA
|
||||
|
||||
### Relevant Articles:
|
||||
- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema)
|
||||
- More articles: [[<--prev]](/persistence-modules/spring-data-jpa-crud)
|
||||
|
||||
### Eclipse Config
|
||||
After importing the project into Eclipse, you may see the following error:
|
||||
"No persistence xml file found in project"
|
||||
|
||||
This can be ignored:
|
||||
- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project"
|
||||
Or:
|
||||
- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator
|
||||
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-jpa-crud-2</artifactId>
|
||||
<name>spring-data-jpa-crud-2</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package com.baeldung.schemageneration;
|
||||
|
||||
import com.baeldung.schemageneration.model.Account;
|
||||
import com.baeldung.schemageneration.model.AccountSetting;
|
||||
import com.baeldung.schemageneration.repository.AccountRepository;
|
||||
import com.baeldung.schemageneration.repository.AccountSettingRepository;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = AccountApplication.class)
|
||||
public class AccountRepositoryIntegrationTest {
|
||||
|
||||
private static final String USER_NAME = "Eduard";
|
||||
private static final String USER_EMAIL_ADDRESS = "[email protected]";
|
||||
private static final String ACCOUNT_SETTING_NAME = "Timezone";
|
||||
private static final String ACCOUNT_SETTING_VALUE = "UTC+02";
|
||||
|
||||
@Autowired
|
||||
private AccountRepository accountRepository;
|
||||
|
||||
@Autowired
|
||||
private AccountSettingRepository accountSettingRepository;
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
accountRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNewAccount_whenSave_thenSuccess() {
|
||||
Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS);
|
||||
accountRepository.save(account);
|
||||
|
||||
assertEquals(1, accountRepository.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSavedAccount_whenFindByName_thenFound() {
|
||||
Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS);
|
||||
accountRepository.save(account);
|
||||
|
||||
Account accountFound = accountRepository.findByName(USER_NAME);
|
||||
|
||||
assertNotNull(accountFound);
|
||||
assertEquals(USER_NAME, accountFound.getName());
|
||||
assertEquals(USER_EMAIL_ADDRESS, accountFound.getEmailAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSavedAccount_whenAccountSettingIsAdded_thenPersisted() {
|
||||
Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS);
|
||||
account.addAccountSetting(new AccountSetting(ACCOUNT_SETTING_NAME, ACCOUNT_SETTING_VALUE));
|
||||
accountRepository.save(account);
|
||||
|
||||
Account accountFound = accountRepository.findByName(USER_NAME);
|
||||
assertNotNull(accountFound);
|
||||
AccountSetting accountSetting = accountSettingRepository.findByAccountId(accountFound.getId());
|
||||
|
||||
assertNotNull(accountSetting);
|
||||
assertEquals(ACCOUNT_SETTING_NAME, accountSetting.getSettingName());
|
||||
assertEquals(ACCOUNT_SETTING_VALUE, accountSetting.getSettingValue());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,9 +8,7 @@ This module contains articles about Spring Data JPA used in enterprise applicati
|
||||
- [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test)
|
||||
- [A Guide to Spring’s Open Session in View](https://www.baeldung.com/spring-open-session-in-view)
|
||||
- [Partial Data Update With Spring Data](https://www.baeldung.com/spring-data-partial-update)
|
||||
- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation)
|
||||
- [Spring JPA – Multiple Databases](https://www.baeldung.com/spring-data-jpa-multiple-databases)
|
||||
- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
|
||||
|
||||
### Eclipse Config
|
||||
After importing the project into Eclipse, you may see the following error:
|
||||
|
||||
@@ -6,7 +6,6 @@ This module contains articles about filtering data using Spring Data JPA
|
||||
- [An Advanced Tagging Implementation with JPA](https://www.baeldung.com/jpa-tagging-advanced)
|
||||
- [A Simple Tagging Implementation with JPA](https://www.baeldung.com/jpa-tagging)
|
||||
- [Spring Data JPA and Null Parameters](https://www.baeldung.com/spring-data-jpa-null-parameters)
|
||||
- [Spring Data JPA Projections](https://www.baeldung.com/spring-data-jpa-projections)
|
||||
|
||||
### Eclipse Config
|
||||
After importing the project into Eclipse, you may see the following error:
|
||||
|
||||
@@ -4,7 +4,6 @@ This module contains articles about querying data using Spring Data JPA .
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Spring Data JPA @Query](https://www.baeldung.com/spring-data-jpa-query)
|
||||
- [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries)
|
||||
- [Hibernate Pagination](https://www.baeldung.com/hibernate-pagination)
|
||||
- [Sorting with Hibernate](https://www.baeldung.com/hibernate-sort)
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.derivedquery;
|
||||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -10,4 +10,4 @@ public class QueryApplication {
|
||||
SpringApplication.run(QueryApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ This module contains articles about querying data using Spring Data JPA
|
||||
|
||||
### Relevant Articles:
|
||||
- [The Exists Query in Spring Data](https://www.baeldung.com/spring-data-exists-query)
|
||||
- [Customizing the Result of JPA Queries with Aggregation Functions](https://www.baeldung.com/jpa-queries-custom-result-with-aggregation-functions)
|
||||
- [Limiting Query Results With JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results)
|
||||
- [Sorting Query Results with Spring Data](https://www.baeldung.com/spring-data-sorting)
|
||||
- [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example)
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
This module contains articles about Spring Data JPA.
|
||||
|
||||
### Relevant Articles:
|
||||
- [New CRUD Repository Interfaces in Spring Data 3](https://www.baeldung.com/spring-data-3-crud-repository-interfaces)
|
||||
- [How to Persist a List of String in JPA?](https://www.baeldung.com/java-jpa-persist-string-list)
|
||||
- [Hibernate Natural IDs in Spring Boot](https://www.baeldung.com/spring-boot-hibernate-natural-ids)
|
||||
- [Correct Use of flush() in JPA](https://www.baeldung.com/spring-jpa-flush)
|
||||
- [Difference Between findBy and findOneBy in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-findby-vs-findoneby)
|
||||
- [How to Get Last Record in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-last-record)
|
||||
- [Refresh and Fetch an Entity After Save in JPA](https://www.baeldung.com/spring-data-jpa-refresh-fetch-entity-after-save)
|
||||
- More articles: [[<-- prev]](../spring-data-jpa-repo-2)
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.baeldung.fetchandrefresh;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class Order {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@OneToMany(mappedBy = "order", fetch = FetchType.EAGER)
|
||||
private List<OrderItem> orderItems;
|
||||
|
||||
private LocalDate orderDate;
|
||||
|
||||
private String name;
|
||||
|
||||
private String customerName;
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<OrderItem> getOrderItems() {
|
||||
return orderItems;
|
||||
}
|
||||
|
||||
public void setOrderItems(List<OrderItem> orderItems) {
|
||||
this.orderItems = orderItems;
|
||||
}
|
||||
|
||||
public LocalDate getOrderDate() {
|
||||
return orderDate;
|
||||
}
|
||||
|
||||
public void setOrderDate(LocalDate orderDate) {
|
||||
this.orderDate = orderDate;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCustomerName() {
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public void setCustomerName(String customerName) {
|
||||
this.customerName = customerName;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user