Migrating from (Spring Data) JPA to Spring Data JDBC by Jens Schauder @ Spring I/O 2024

  Рет қаралды 18,123

Spring I/O

Spring I/O

Күн бұрын

Пікірлер: 30
@AgroTuna
@AgroTuna 6 ай бұрын
I migrated a medium sized project to spring data jdbc and was impressed by how straightforward it was. Sure there were some things that had to be changed, ran into a few footguns along the way, but in the end it simplified the code and opened my eyes to all of the "magic" that was happening behind the scenes in the JPA implementation.
@jesprotech
@jesprotech 7 ай бұрын
I can understand why some people would be wandering off to another session just by reading the title and indeed: "why would anyone spend their time migrating from JPA to JDBC?". It contradicts the whole idea of having created JPA in the first place! But I think Jens explain well why this could be a possibility. Great work!
@TheodoreRavindranath
@TheodoreRavindranath 2 ай бұрын
Very useful presentation... whenever going for a new technology, the modelling changes and these kind of presentations are beneficial which explain how the model should be reworked. Not only that, but the approach to move from A to B is also explained nicely.
@kevinmaltby4202
@kevinmaltby4202 2 ай бұрын
33:57 Wouldn't it be better to use the KeyHolder class to get the ID because you're having to know the internals i.e. the sequence name, herer?. I would have thought many schemas would declare their id as some sort of auto-incrementing sequence and not care or declare its name e.g. postgres's `bigserial`.
@michachlebikpiotrowski7713
@michachlebikpiotrowski7713 6 ай бұрын
Based on my experience - for simple pet-projects, or greenfield microservice-style that would work perfectly. For the long-developed humongous monoliths, it's just impossible to introduce. It's not just a code/persistence layer change, but also a mental switch from anemic model to richer model (in DDD style) plus teaching a lot of people what aggregates, bounded contexts or ACLs are. And I know that the author admits that it's a lot of work, but in general - for big monoliths, it would be time better spend introducing strangler pattern, and just eventually migrating to microservices.
@soheiljahangirie2477
@soheiljahangirie2477 4 ай бұрын
That was a great presentation. learned a lot
@hardcorecode
@hardcorecode 7 ай бұрын
JDBC have no support for composite keys or embeddables... so how is JPA to JDBC migration going to work?
@sonayyalim
@sonayyalim 6 ай бұрын
It does have support for embeddables. Not sure about composite keys, there is a way I imagine it could be done but can't guarantee it will be as smooth as hibernate does.
@hardcorecode
@hardcorecode 6 ай бұрын
@@sonayyalim No support for simple composite keys I checked!
@HeyHoLetsGo32
@HeyHoLetsGo32 5 ай бұрын
Composite keys are almost a code smell to me. They introduce business logic, and that should be part of the service layer. Technical IDs should totally suffice, and if you can't ensure some stuff from service layer for some reason, there is still an optioin of introducing unique constraints, for example. Ever tried to "foreign key reference" something that has a composite key? Becomes messy quickly.
@hardcorecode
@hardcorecode 5 ай бұрын
@@HeyHoLetsGo32 completely disagree, nevertheless I should have the option to choose. yes, I have tried to foreign key reference a composite key. it was trivial with JPA!
@HeyHoLetsGo32
@HeyHoLetsGo32 5 ай бұрын
@@hardcorecode well you most certainly can choose jpa, no one deprecates it. Just from experience with large projects, „over-engineering“ most certainly creates hard to understand code over time. With fluctuations and „fresh“ devs every now and then, less magic tends to „work out“ nicer. But of course, if you have devs well trained in JPA, and will have in the future, it’s a viable option. My main pain point of JPA are the mutable entity classes anyway.
@walterkivindu1470
@walterkivindu1470 6 ай бұрын
I have just watched the video but I don't agree with his mapping between Shipment and Item domain model. I don't know you can achieve One--to-Many entity relationship between Shipment and Item, such that a shipment can have many items, with that mapping.
@Mihey77
@Mihey77 6 ай бұрын
Spring Data JDBC has a lot of limitations, which are not explicitly documented, e.g. no derived delete clauses. But the most excruciating part is deleting and inserting child entities on updates, since SD JDBC is unable to track what changed and what did not. This all seemed fine when the project just started, but what I see through these years is that the development speed has slowed down and there aren't many improvements lately.
@xmicore
@xmicore 6 ай бұрын
simply schauderhaft
@pierrelaurensflorez2273
@pierrelaurensflorez2273 7 ай бұрын
I haven't watched the video yet, but my first question is.... why would I migrate from JPA to JDBC?
@AntonArhipov
@AntonArhipov 7 ай бұрын
And that's the question Jens asks from the audience right in the beginning :)
@zombi1034
@zombi1034 7 ай бұрын
Most likely if you encounter problems with your JPA implementation which you (think you) can’t solve with JPA.
@walterkivindu1470
@walterkivindu1470 6 ай бұрын
For speed and reduce memory footprint
@HeyHoLetsGo32
@HeyHoLetsGo32 5 ай бұрын
For me, the main reason is that now I can annotate records with @Table. No need for mutability with a no-args constructor and setters as JPA requires. Takes away a whole level of mapping for me.
@Mig440
@Mig440 7 ай бұрын
Keep your @java annotations away from MY domain model please and please don't infect my domain model with persistence concerns.
@roman-proshin
@roman-proshin 7 ай бұрын
That's a big step forward JDBC does comparing to JPA: entities are now real objects, not magical proxies created by Hibernate. And there is another huge advantage not mentioned in the video: entities can now be immutable! Which is hardly achievable with JPA.
@Mig440
@Mig440 7 ай бұрын
@@roman-proshin That is nice indeed, it would just be nice if you could programmatically separate the mapping logic from the entity type and not having to mix the two. I would probably be on the cautious side and choose to separate domain entities from persistence entities since they each serve different purposes. That keeps the annotations away and having to take on a dependency to Spring JDBC inside the core domain.
@roman-proshin
@roman-proshin 7 ай бұрын
@@Mig440 yes, I definitely agree: it’s a definitive solution when domain classes have no “database” details at all. However, sometimes compromises are an unavoidable evil 🤷‍♂️ As otherwise a converter for every “entity - DB mapping” is required.
@Mig440
@Mig440 7 ай бұрын
@@roman-proshin Sure but then your are explicitly tying YOUR domain with that of Spring JDBC. That can be OK, but then you are expressing a willingness to follow and always be compliant with whatever spring JDBC decides to do in all future iterations. If you are prepared for such effort, that is fine, but I think creating mappers between independent domain objects and persistence objects is a small price to pay for independence. I like to not mix the two if I can help it, but for the regular CRUD apps most are building you are just putting a fancy dressing on SQL anyhow. In fact if that is all you do, why are you then not using something much more simple than a whole web tech stack on top. You might aswell just use postGREST then; no need for a separate web application tier.
@abccbaandy
@abccbaandy 6 ай бұрын
@@roman-proshin Agree, never understand why hibernate do so many magic in default. Just google "LazyInitializationException", you will find you are not the only one who get fucked by hibernate. But JPA concept is fine though.
@NeerajKumar-ej8yo
@NeerajKumar-ej8yo 6 ай бұрын
I am not going to migrate to Spring JDBC, even in new projects I am using JPA ;)
Bootiful Spring Boot 3.x by Josh Long @ Spring I/O 2024
54:26
Spring I/O
Рет қаралды 33 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Spring Tips: Spring Data JDBC
27:36
SpringDeveloper
Рет қаралды 23 М.
Spring Boot APIs Gateway in 20 Minutes
22:50
The IT Wizard
Рет қаралды 14 М.