Skip to content

Commit 3b25395

Browse files
committed
[BAEL-9370] Introduced module with spring-data-jpa repositories:
- one without using AOT repositories - one with AOT repositories - one {what} Will compare the performance of each solution
1 parent cdcc7a2 commit 3b25395

File tree

58 files changed

+1867
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1867
-0
lines changed

persistence-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<module>spring-data-jpa-repo</module>
110110
<module>spring-data-jpa-repo-2</module>
111111
<module>spring-data-jpa-repo-4</module>
112+
<module>spring-data-jpa-repo-5</module>
112113
<module>spring-data-jdbc</module>
113114
<module>spring-data-jpa-simple</module>
114115
<module>spring-data-keyvalue</module>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>spring-data-jpa-repo-5</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<modules>
12+
<module>spring-data-jpa-aot</module>
13+
<module>spring-data-jpa-aot-native-image</module>
14+
<module>spring-data-jpa-not-aot</module>
15+
</modules>
16+
17+
<parent>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-parent</artifactId>
20+
<version>4.0.0-RC1</version>
21+
</parent>
22+
23+
<properties>
24+
<java.version>25</java.version>
25+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26+
</properties>
27+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
```shell
3+
mvn clean install
4+
```
5+
1) run using maven and the spring-boot plugin:
6+
```shell
7+
mvn spring-boot:run
8+
```
9+
Startup times:
10+
`Root WebApplicationContext: initialization completed in 916 ms`
11+
`Started Application in 2.231 seconds`
12+
13+
```shell
14+
java -Dspring.aot.enabled=true \
15+
-Dspring.aot.repositories.enabled=true \
16+
-agentlib:native-image-agent=config-output-dir=target/native-image-hints \
17+
-jar target/spring-data-jpa-aot-0.0.1-SNAPSHOT-exec.jar
18+
```
19+
Startup times:
20+
`Root WebApplicationContext: initialization completed in 440 ms`
21+
`Started Application in 3.26 seconds`
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>spring-data-jpa-repo-5</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>spring-data-jpa-aot-native-image</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-web</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-data-jpa</artifactId>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>com.h2database</groupId>
26+
<artifactId>h2</artifactId>
27+
<scope>runtime</scope>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
</dependencies>
36+
37+
<profiles>
38+
<profile>
39+
<id>native-image</id>
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.graalvm.buildtools</groupId>
44+
<artifactId>native-maven-plugin</artifactId>
45+
<extensions>true</extensions>
46+
<configuration>
47+
<mainClass>com.baeldung.spring.aotrepository.Application</mainClass>
48+
<skipNativeTests>true</skipNativeTests>
49+
<fallback>false</fallback>
50+
<verbose>true</verbose>
51+
<buildArgs>
52+
<arg>--enable-sbom=cyclonedx</arg>
53+
<arg>-H:+UnlockExperimentalVMOptions</arg>
54+
<buildArg>-Ob</buildArg>
55+
<!-- <buildArg>&#45;&#45;trace-object-instantiation=org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl$1</buildArg>-->
56+
<!-- <arg>-H:ServiceLoaderFeatureExcludeServices=org.hibernate.bytecode.spi.BytecodeProvider</arg>-->
57+
<arg>-H:+AllowIncompleteClasspath</arg>
58+
<arg>-H:+ReportExceptionStackTraces</arg>
59+
<!-- <arg>-H:+TraceNativeToolUsage</arg>-->
60+
<!-- <arg>-H:+PrintAOTCompilation</arg>-->
61+
<!-- <arg>&#45;&#45;link-at-build-time</arg>-->
62+
<!-- fixes the aot issue: "Provider org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl could not be instantiated" -->
63+
<buildArg>--trace-object-instantiation=org.hibernate.bytecode.internal.bytebuddy.BytecodeProviderImpl$1</buildArg>
64+
</buildArgs>
65+
</configuration>
66+
</plugin>
67+
<plugin>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-maven-plugin</artifactId>
70+
<configuration>
71+
<mainClass>com.baeldung.spring.aotrepository.Application</mainClass>
72+
<jvmArguments>
73+
-agentlib:native-image-agent=config-output-dir=target/classes/META-INF/native-image/com.baeldung/spring-data-jpa-aot-native-image-additional-hints/
74+
</jvmArguments>
75+
<!-- <image>-->
76+
<!-- <builder>paketobuildpacks/builder:tiny</builder>-->
77+
<!-- <env>-->
78+
<!-- <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>-->
79+
<!-- </env>-->
80+
<!-- </image>-->
81+
</configuration>
82+
<!-- <executions>-->
83+
<!-- <execution>-->
84+
<!-- <id>process-aot</id>-->
85+
<!-- <goals>-->
86+
<!-- <goal>process-aot</goal>-->
87+
<!-- </goals>-->
88+
<!-- </execution>-->
89+
<!-- <execution>-->
90+
<!-- <id>build-image</id>-->
91+
<!-- <goals>-->
92+
<!-- <goal>build-image-no-fork</goal>-->
93+
<!-- </goals>-->
94+
<!-- </execution>-->
95+
<!-- </executions>-->
96+
</plugin>
97+
</plugins>
98+
</build>
99+
</profile>
100+
</profiles>
101+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.spring.aotrepository;
2+
3+
import org.apache.commons.logging.Log;
4+
import org.apache.commons.logging.LogFactory;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.boot.system.JavaVersion;
8+
9+
@SpringBootApplication
10+
public class Application {
11+
12+
private static final Log logger = LogFactory.getLog(Application.class);
13+
14+
public static void main(String[] args) {
15+
logger.info("Application starts..");
16+
logger.info("Java version: " + System.getProperty("java.version"));
17+
logger.info("Java version: " + JavaVersion.getJavaVersion());
18+
19+
SpringApplication.run(Application.class, args);
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.Id;
7+
import jakarta.persistence.Table;
8+
9+
@Entity
10+
@Table(name = "ADDRESS")
11+
public class Address {
12+
13+
@Id
14+
@GeneratedValue
15+
private Long id;
16+
private String street;
17+
private String city;
18+
@Column(name = "post_code")
19+
private String postCode;
20+
21+
public Long getId() {
22+
return id;
23+
}
24+
25+
public void setId(Long id) {
26+
this.id = id;
27+
}
28+
29+
public String getStreet() {
30+
return street;
31+
}
32+
33+
public void setStreet(String street) {
34+
this.street = street;
35+
}
36+
37+
public String getCity() {
38+
return city;
39+
}
40+
41+
public void setCity(String city) {
42+
this.city = city;
43+
}
44+
45+
public String getPostCode() {
46+
return postCode;
47+
}
48+
49+
public void setPostCode(String postCode) {
50+
this.postCode = postCode;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return "User[id=" + id + ", street=" + street + ", city=" + city + ", postCode=" + postCode + "]";
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
import jakarta.persistence.Table;
6+
7+
@Entity
8+
@Table(name = "INVENTORY")
9+
public class Inventory {
10+
11+
@Id
12+
private Long productId;
13+
private Long balance;
14+
15+
public Long getProductId() {
16+
return productId;
17+
}
18+
19+
public void setProductId(Long productId) {
20+
this.productId = productId;
21+
}
22+
23+
public Long getBalance() {
24+
return balance;
25+
}
26+
27+
public void setBalance(Long balance) {
28+
this.balance = balance;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "Order [productId=" + productId + ", balance=" + balance + "]";
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
import jakarta.persistence.Table;
6+
7+
@Entity
8+
@Table(name = "ORDERS")
9+
public class Order {
10+
11+
@Id
12+
private Long id;
13+
private String productId;
14+
private Long amount;
15+
16+
public Long getId() {
17+
return id;
18+
}
19+
20+
public void setId(Long orderId) {
21+
this.id = orderId;
22+
}
23+
24+
public String getProductId() {
25+
return productId;
26+
}
27+
28+
public void setProductId(String productId) {
29+
this.productId = productId;
30+
}
31+
32+
public Long getAmount() {
33+
return amount;
34+
}
35+
36+
public void setAmount(Long amount) {
37+
this.amount = amount;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "Order [productId=" + productId + ", id=" + id + ", amount=" + amount + "]";
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
import jakarta.persistence.Table;
6+
7+
@Entity
8+
@Table(name = "PRODUCTS")
9+
public class Product {
10+
11+
@Id
12+
private Long id;
13+
private String name;
14+
private double price;
15+
16+
public Product() {
17+
super();
18+
}
19+
20+
private Product(Long id, String name, double price) {
21+
super();
22+
this.id = id;
23+
this.name = name;
24+
this.price = price;
25+
}
26+
27+
public Long getId() {
28+
return id;
29+
}
30+
31+
public void setId(final Long id) {
32+
this.id = id;
33+
}
34+
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public void setName(final String name) {
40+
this.name = name;
41+
}
42+
43+
public double getPrice() {
44+
return price;
45+
}
46+
47+
public void setPrice(final double price) {
48+
this.price = price;
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return "Product [name=" + name + ", id=" + id + ", price=" + price + "]";
54+
}
55+
}

0 commit comments

Comments
 (0)