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.
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.
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!
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.
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`.
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.
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.
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.
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.
@@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!
@@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.
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.
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.
@@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.
@@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.
@@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.
@@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.
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.
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.
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!
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.
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`.
That was a great presentation. learned a lot
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.
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.
simply schauderhaft
JDBC have no support for composite keys or embeddables... so how is JPA to JDBC migration going to work?
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.
@@sonayyalim No support for simple composite keys I checked!
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.
@@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!
@@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.
I haven't watched the video yet, but my first question is.... why would I migrate from JPA to JDBC?
And that's the question Jens asks from the audience right in the beginning :)
Most likely if you encounter problems with your JPA implementation which you (think you) can’t solve with JPA.
For speed and reduce memory footprint
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.
Keep your @java annotations away from MY domain model please and please don't infect my domain model with persistence concerns.
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.
@@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.
@@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.
@@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.
@@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.
I am not going to migrate to Spring JDBC, even in new projects I am using JPA ;)