Spring Web App Flashcards

1
Q

List vs. Set in @OneToMany JPA

A

Sets are preferable to use with too many relationships for several reasons!!!!!
First, in most cases, the collection that doesn’t allow duplicates reflects the domain model perfectly. We cannot have two identical users in a group, and a user cannot have two identical posts.

Another thing is that Sets are more flexible. While the default fetch mode for Sets is to create a join, we can define it explicitly by using fetch mode.

The delete behavior for many-to-many relationships using Lists produces an overhead. It’s hard to notice the difference on small datasets, but we can experience high latency with lots of data.

To avoid these problems, it’s a good idea to cover the crucial parts of our interaction with the database with tests. It would ensure that some seemingly insignificant change in one part of our domain model won’t introduce huge overhead in generated queries.

  1. Conclusion
    In most situations, we should use Sets for to-many relationships. This provides us with mode controllable relationships and avoids overheads on deletes.

However, all the changes and ideas about improving the domain model should be profiled and tested. The issues might not expose themselves to small datasets and simplistic entity relationship

https://www.baeldung.com/spring-jpa-onetomany-list-vs-set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Spring initialiser dep:
web,
JPA
H2 DB(in memory DB)
Security
thymeleaf

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Thymeleaf

A

By default, Spring Boot configures the Thymeleaf template engine to read template files from /resources/templates .

Effectively, you as the developer just need to start making Thymeleaf templates and dropping them into /resources/templates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly