Spring Tips: Spring Data JDBC

Поділитися
Вставка
  • Опубліковано 28 лис 2024

КОМЕНТАРІ • 43

  • @arnaudpoutieu1331
    @arnaudpoutieu1331 10 місяців тому +8

    Thanks, Josh. Software solutions design/architecture should always be guided by "Make it Simple" attitude in priority! You rock man

  • @zakb.7108
    @zakb.7108 10 місяців тому +1

    Care to see as well how strategies can be implemented with spring batch. For one thing using lazy loading and batch size for the entities in the first level cache seems pretty handy to me..

  • @joachimdietl6737
    @joachimdietl6737 10 місяців тому +4

    Please Josh do some tutorial about composed primary keys and this embededable thing. I think many devs are looking for it

  • @vijaydeenanth
    @vijaydeenanth 9 місяців тому

    I use hibernate to persists data and use it to read data back where i need to fetch by id to update. Other than that all views are Sql Coded in mybatis. I like the approach that gives me full control on sql when I have multiple joins. I dont get compile time type safety in mybatis, but my tests help to remove any errors that might arise in runtime

  • @v.deepak
    @v.deepak 10 місяців тому +22

    I tried to explain this to everyone, nobody paying attention, they are happy with hibernate complexity 😢

    • @javasoccernut
      @javasoccernut 10 місяців тому +4

      It isnt that complex. Spring Data JDBC has its own complexities. Trade offs.

    • @coffeesoftware
      @coffeesoftware 10 місяців тому +1

      100%. If you truly have the sprawling complexity where Hibernate makes sense, then by all means use spring data jpa. But for most of us, there’s JavaOOQ, MyBatis, Spring Data JDBC, etc., all of which cost less in terms of performance and give us as good or better simplicity upfront. The nice thing about Spring Data is that the boring stuff looks basically the same if you ever need to move to JPA. You’d only have to worry about the complexity of entities and queries

    • @dominikseljan3043
      @dominikseljan3043 10 місяців тому +1

      I wish we move away from hibernate but I don’t think that’s going to happen any time soon

    • @javasoccernut
      @javasoccernut 10 місяців тому +1

      ​ugh, lost my reply.
      Short version. this is opinion and theory. I have decades of hands on real world experience that says otherwise.
      I use JPA with small and large apps. Works great. It is performant. But I dont treat it like an Object Database.
      The issue is that people dont learn to use the tools wisely and blame the tool.
      We swtiched from JPA to JDBC and it was not a minor change though still easier with Spring Data and we had flat models. It wasnt more peformant.
      the things you meantioned are options but ones MMV. there are trade offs

  • @levenchen9692
    @levenchen9692 10 місяців тому +2

    Thanks,Josh. What's is uao command?

  • @mondikoci2966
    @mondikoci2966 10 місяців тому

    Thanks for the demo.

  • @antonsiniaiev1151
    @antonsiniaiev1151 10 місяців тому +4

    Does data jdbc support composite primary keys and json fields?

    • @hardcorecode
      @hardcorecode 8 місяців тому

      no support for composite primary keys

  • @drewenia
    @drewenia 9 місяців тому +1

    What keyboard are you using? And keyboard switches?

  • @garethbaker5179
    @garethbaker5179 7 місяців тому

    How would you import this project into a spring-boot project such that spring-boot doesnt demand that the classes in your JdbcApplication have to be defined as Beans?

  • @johng.weller468
    @johng.weller468 6 місяців тому

    The Profile field is not embedded inside the Customer object; how is it possible to save both of them with one repository using spring data jdbc?

  • @zakb.7108
    @zakb.7108 10 місяців тому

    What about Mybatis? We are using it in my current position but I don't know to which extent can we mix both for repositories

  • @shashankbajpai5659
    @shashankbajpai5659 6 місяців тому

    Can you provide your schema somewhere so that we can easily follow your tutorial?

  • @essamal-mansouri2689
    @essamal-mansouri2689 10 місяців тому +3

    You should consider jooq instead of jdbc. You wouldn't be getting "bad sql" errors at runtime like you got and it is also not using reflection, etc. and you are no longer limited to the crud operations that you are limited to here

    • @javasoccernut
      @javasoccernut 10 місяців тому +1

      what are the Cons?

    • @dominikseljan3043
      @dominikseljan3043 10 місяців тому +1

      Cons are that it’s expensive as hell if you are not using an open source DB

    • @javasoccernut
      @javasoccernut 10 місяців тому

      if someone wants this, they can use ...i forget the name right now, but it can generate query models and it works with SPring Data and is true opensource.

  • @essamal-mansouri2689
    @essamal-mansouri2689 10 місяців тому +1

    Do you recommend that people use this and not use reactive drivers and all that anymore now that we have loom

    • @javasoccernut
      @javasoccernut 10 місяців тому +1

      the spring docs say (or use to) that for most apps reactive is mostly YAGNI and adds complexity.
      That is my experience over the decades.
      Code for maintenance. Optimize where needed.

  • @MuayViaura
    @MuayViaura 3 місяці тому

    Where is join cases?

  • @AdelmarSitz
    @AdelmarSitz 3 місяці тому

    What is mean repository?

  • @suikast420
    @suikast420 10 місяців тому

    21:00 if using chances in java , then do not use the default serilizer of java.

  • @esafzay
    @esafzay 4 місяці тому

    That was good, but why do you always write all the code in one file?

  • @peterabiodunokusolubo1541
    @peterabiodunokusolubo1541 3 місяці тому

    I wish spring boot data jdbc was earlier than hibernate ....

  • @DuongTran-zh6td
    @DuongTran-zh6td 10 місяців тому

    spring kafka teacher oi,

  • @javasoccernut
    @javasoccernut 10 місяців тому

    I'd love to share this Josh but the comments about Hibernate are not accurate.
    I've done RDBMS without and with Hibernate for 30 years. I don't want to go back.
    That being said, where there are issues is when you have an existing db that is poorly designed.
    Recently I had to switch to Spring Data JDBC because of this. But only because Hibernate made some change that seems to cache data types and our db deployments are not consistent and so it would occasionally blow up queries.This is not Hibernate's fault.

  • @allo5auru5
    @allo5auru5 10 місяців тому +2

    Data JPA should still be the default for most medium to big apps. Using Data JDBC may be premature optimization.

    • @holothuroid9111
      @holothuroid9111 10 місяців тому +1

      You say "should". Care to explain that value judgement?

    • @javasoccernut
      @javasoccernut 10 місяців тому

      In my humble experience (3 decades) this is the case. YMMV.

    • @bariole
      @bariole 10 місяців тому

      No it shouldn't. You should be able to explain why you need Hibernate. Majority of time Hibernate is net negative when compared to JDBC. You end up with more code, and worse problems.

    • @javasoccernut
      @javasoccernut 10 місяців тому

      ​@@bariole that is theory or your experience. Spring Data JDBC is not just JDBC. If you do raw Hibernate, potentially. But ORMs exist to reduce the code you'd need to write without it. We just converted from Spring Data JPA to Spring Data JDBC. It was not less code. FWIR it was more. If we had not treated JPA as a table mapper, it for sure would have been.

    • @bariole
      @bariole 10 місяців тому

      @javasoccernut Experience. Properly written Hibernate results in more code, as you need a lot of code to handle level 1 cache issues and navigate the idiosyncrasies of the context-dependent grammar of JPA/Hibernate mapping. You also need to enforce a bunch of rules, such as updates from the root, which can be challenging to explain to users who "just need SQL," etc. For the majority of people, merges seem to work like "magic." Additionally, if the application is written by relatively inexperienced individuals (which is why you are here fixing it), it will likely contain more queries than necessary, regardless of whether they are SQL or HQL. However, it is much easier to clean up directly mapped code, such as ActiveRecord, JDBC, JdbcTemplate, or MyBatis.
      In my 20 years of experience, I have encountered maybe five projects where the ObjectMapper pattern implementation made sense, primarily due to practical reasons such as "I need to generate SQL for multiple backends," "I need optimistic locking," or "I am using JHipster, and that is what it uses." Even Martin Fowler, the person who invented the whole pattern, stated back in 2012 that the way to fix ORMs is by keeping your model flat and in a direct one-to-one mapping with rows. Essentially, this involves fully ignoring relation mapping and relegating Hibernate's role to a "SQL generator." This approach is similar to what is presented here but without all the double-state management issues of ORMs. Most of the time, Hibernate/JPA/EclipseLink are more complex than the problems they are trying to solve.

  • @olivierboisse1678
    @olivierboisse1678 10 місяців тому

    19:36 cheating 😄

  • @remek712
    @remek712 10 місяців тому

    All those things that you explained will be in future automatically handled by AI