Spring Data JDBC - Many to Many Relationships

  Рет қаралды 17,797

Maciej Walkowiak 🍃 Spring Academy

Maciej Walkowiak 🍃 Spring Academy

Күн бұрын

Пікірлер: 15
@carolineliu6938
@carolineliu6938 2 ай бұрын
Thanks for the great examples! And looking forward to more cat please!
@davidljuba6698
@davidljuba6698 6 жыл бұрын
"To wrap it up: Spring Data JDBC does not support many-to-one or many-to-many relationships. In order to model these, use IDs. This encourages a clean modularization of the domain model. It also removes a whole type of questions that one would have to solve and learn to reason about if such a mapping were possible." Good to know, from link you provide. Thanks for good content.
@SpringAcademy
@SpringAcademy 6 жыл бұрын
Thanks David! What are your thoughts about this project? I think once Spring Data JDBC matures it will become a default option for using relational databases with Spring.
@davidljuba6698
@davidljuba6698 6 жыл бұрын
@@SpringAcademy What I found problematic about JPA, is that, it has tendency to lead developers to tightly couple modules (in monolith applications). I mean, ability to create many-to-many or many-to-one relationships in way that is done in JPA, could be source of problem, аs nothing prevent you to do that way, where, at the end, persistence layer has all entities mixed, and all modules depends on it. So, I am not sure, why many-to-many or many-to-one is not currently implemented in Spring Data Jdbc, could be implementation complexity or strong principles behind this (DDD), but it seams to me that second one is reason, what I just learned from your video аnd link you provided, and I am happy because of that! Quote from your video: "There is issue with that approach (JPA many-to-many relationship), like circular dependency and no clear ownership between entities", sentence was most valuable for me. Data duplication and maintaining it is a new problem, and increases complexity again, but in more maintainable way (I think CQRS and ES are solving this problem). I was researching about this ("data duplication DDD") and found many interesting articles: "Instead of system B exposing methods for creating and updating customers that when used by System A would cause a synchronous dependency, Julies uses an event-based approach using a message queue to implement the publish-subscribe pattern. System A will then publish events by sending messages about created and updated customer, messages that system B listens to and updates its database. Using this technique system B will end up having a complete list of customers but only with a small amount of data compared to system A." ( www.infoq.com/news/2014/11/sharing-data-bounded-contexts ) After all, everything I stated here is my opinion, so don't take it 100% correct.
@SpringAcademy
@SpringAcademy 6 жыл бұрын
@@davidljuba6698 definitely Spring Data JDBC is more opinionated than JPA - I also like it, in the end it leads to better design and if one doesn't want to follow aggregate oriented model or do something hacky it's always possible to just use plain SQL query either with Spring Data JDBC or JOOQ. Btw, good modularity and following DDD principles is also possible with JPA but since it's so easy to just put @ManyToX many developers just do it without considering other options. Regarding data duplication - thanks for the link! CQRS and ES are nice tools to solve this problem, but it can be easily done even without introducing these patterns. Spring Data has a base class AbstractAggregateRoot that makes it super easy to publish events from entities and then forward them to a queue from which another service or even same service but different module can listen to. The only one correct answer to all the questions is "it depends" ;)
@tohidfla
@tohidfla 5 жыл бұрын
now after couple of time watching I have understood this video :)))) I hope there will gonna be more videos like this from you.
@alexpishvanov736
@alexpishvanov736 Жыл бұрын
When cat has disappeared in just one glance I was scared )))
@kunalvarpe40
@kunalvarpe40 2 жыл бұрын
@Spring Academy I have tried the above code for many to many relation for spring boot 2.7.5 it is not working as expected. It is giving error "java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: book_author". Anyone has any idea. I am not able to find any guide for newer version if anything is changed.
@samm4515
@samm4515 2 жыл бұрын
Thanks, but what kind of editor are you using? Visual Studio Code ? Or something else ?
@Importunity
@Importunity 4 жыл бұрын
I'm wondering why you didnt use a composite key instead you used long author?
@jesusveliz2150
@jesusveliz2150 2 жыл бұрын
Excelete muy genial sus vidos, tengo una consulta para la relación ManyToMany. Como harias para recuperar solos los libros que coincidan entre los autores. Por ejemplo del lado del libro: categoría=acción Se desea obtener todos los actores que hayan escrito un libro de acción. { Autores:{[ { IdAutor:1, Nombre:"AA" }, { IdAutor:2, Nombre:"BB" } ]}, Libros{[ IdLibro:1 CategoríaLibro:"accion" ]} } Como puedes ver, quisiera obtener esa salida pero lo le ve la vuelta.
@rabinneupane5906
@rabinneupane5906 9 ай бұрын
How to make 1 book with multiple authors?
@JeaneAdix
@JeaneAdix 4 жыл бұрын
Hi, thank you for the video, in my code i do i have a many to many on a "code""tag" Where I use a Set in tags and a Set in codes. I use fetch type eager, but this is very slow.... I am using springJPA (persistencex) library, can I still use this trick?
@teratoma.
@teratoma. 4 жыл бұрын
yugi spitting facts
@vishalsundararajan1228
@vishalsundararajan1228 3 жыл бұрын
or we could just drop many to many mapping and have duplicate entries in the book table with authorid as foreign key with book and authorid as combined unique constraint. Now this will basically covert a many to many to one to many
Introduction to Spring Data JDBC
10:10
Maciej Walkowiak 🍃 Spring Academy
Рет қаралды 24 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
#12 Hibernate Tutorial | Mapping Relations Theory
13:14
Telusko
Рет қаралды 313 М.
Spring Data JDBC - Repositories
6:40
Maciej Walkowiak 🍃 Spring Academy
Рет қаралды 6 М.
Spring Data JDBC - One to One & One to Many Relationships
10:20
Maciej Walkowiak 🍃 Spring Academy
Рет қаралды 21 М.
⏰ Spring Boot @Scheduled Crash Course
14:21
Maciej Walkowiak 🍃 Spring Academy
Рет қаралды 60 М.
Spring Puzzle - The one thing you must know about Hibernate & JPA!
8:00
Maciej Walkowiak 🍃 Spring Academy
Рет қаралды 4,2 М.
Введение в Spring Data Jdbc // Демо-занятие курса «Java Developer. Professional»
1:35:58
OTUS IT Онлайн - образование
Рет қаралды 3,7 М.
Best Practices for Many-To-One and One-To-Many Association Mappings
9:35
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН