Spring Tips: Spring Data JDBC

Поделиться
HTML-код
  • Опубликовано: 8 янв 2024
  • Hi, Spring fans! In this installment, Josh Long looks at the fantastic Spring Data JDBC project, which is one of the easiest and most powerful ways to leverage JDBC in a Spring Boot application. #postgresql #java #springboot #jdbc #architecture #code #java21
  • НаукаНаука

Комментарии • 38

  • @arnaudpoutieu1331
    @arnaudpoutieu1331 5 месяцев назад +7

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

  • @mondikoci2966
    @mondikoci2966 4 месяца назад

    Thanks for the demo.

  • @joachimdietl6737
    @joachimdietl6737 5 месяцев назад +4

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

  • @zakb.7108
    @zakb.7108 4 месяца назад +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..

  • @vijaydeenanth
    @vijaydeenanth 3 месяца назад

    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 5 месяцев назад +19

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

    • @javasoccernut
      @javasoccernut 5 месяцев назад +3

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

    • @coffeesoftware
      @coffeesoftware 5 месяцев назад +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 5 месяцев назад +1

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

    • @javasoccernut
      @javasoccernut 4 месяца назад +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 4 месяца назад +2

    Thanks,Josh. What's is uao command?

  • @zakb.7108
    @zakb.7108 4 месяца назад

    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

  • @drewenia
    @drewenia 3 месяца назад

    What keyboard are you using? And keyboard switches?

  • @antonsiniaiev1151
    @antonsiniaiev1151 5 месяцев назад +3

    Does data jdbc support composite primary keys and json fields?

    • @macctosh
      @macctosh 2 месяца назад

      no support for composite primary keys

  • @johng.weller468
    @johng.weller468 17 дней назад

    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?

  • @garethbaker5179
    @garethbaker5179 Месяц назад

    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?

  • @essamal-mansouri2689
    @essamal-mansouri2689 5 месяцев назад +1

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

    • @javasoccernut
      @javasoccernut 5 месяцев назад +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.

  • @shashankbajpai5659
    @shashankbajpai5659 17 дней назад

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

  • @DuongTran-zh6td
    @DuongTran-zh6td 4 месяца назад

    spring kafka teacher oi,

  • @suikast420
    @suikast420 5 месяцев назад

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

  • @essamal-mansouri2689
    @essamal-mansouri2689 5 месяцев назад +2

    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 5 месяцев назад +1

      what are the Cons?

    • @dominikseljan3043
      @dominikseljan3043 5 месяцев назад +1

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

    • @javasoccernut
      @javasoccernut 4 месяца назад

      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.

  • @javasoccernut
    @javasoccernut 5 месяцев назад

    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.

  • @andreiz82
    @andreiz82 5 месяцев назад +2

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

    • @holothuroid9111
      @holothuroid9111 5 месяцев назад +1

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

    • @javasoccernut
      @javasoccernut 5 месяцев назад

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

    • @bariole
      @bariole 4 месяца назад

      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 4 месяца назад

      ​@@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 4 месяца назад

      @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 4 месяца назад

    19:36 cheating 😄

  • @remek712
    @remek712 4 месяца назад

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