Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions integration/spring_jpa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
Binary file not shown.
2 changes: 2 additions & 0 deletions integration/spring_jpa/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
31 changes: 31 additions & 0 deletions integration/spring_jpa/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
= JPA Example

Examples prepared to explain the below concepts.

1. Use Lazy loading
2. Usage of java.time.localdate.
3. Enum usage with converter


=== Lazy loading

Always advised to use lazy loading. Lazy loading fetches data only when it is really required. This example uses FetchType Lazy, the invited guests will be loaded only on demand.

A `SELECT` query applied for fetching booking or bookings will not fetch any invited guests. The below statement fetches all guests for a particular booking. It executes a `SELECT` query with booking id as arguement.
`BookingEntity.getInvitedGuests()`


=== Enum

Using Converter annotation convert an entity attribute to a database value and vice versa. In this example, enum defined as BOOKED("B"), and NOTBOOKED("N") and CANCELED ("C"). This helps to make sure the code is not broken by refactorings.

The other two ways to deal with enums are by their `Ordinal` or by `name`. `Ordinal` may not be a good choice, if someone changes the places of the items in enum, wrong integer value may be stored.

=== LocalDateTime

java.time.LocalDateTime used instead of java.util.date, major benefits are:

* LocalDateTime API has its own format/parse methods.
* Addition/subtraction operation are easier (minusMinutes,plusDays etc.)


316 changes: 316 additions & 0 deletions integration/spring_jpa/mvnw

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading