Hibernate & JPA Tutorial - Crash Course

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ก.ค. 2024
  • Ever looked for a comprehensive tutorial to Hibernate & JPA that is fun and entertaining at the same time?
    This video is a crash course into the Hibernate & JPA universe. We'll start with getting the correct project dependencies, annotating our classes with JPA annotations and setting up a SessionFactory. This allows us to execute basic CRUD operations, HQL and Criteria queries. Afterwards we can simply JPAify our code, switching out a couple of classes and you'll understand how Hibernate / JPA & Spring Boot play together. By the end of it, you'll have a good (initial) understanding of how to use it and what your future Hibernate / JPA learning journey entails.
    ► Source Repository
    github.com/marcobehlerjetbrai...
    ► Timestamps
    00:00 Intro - What you need to know about Hibernate
    00:39 What problem does it solve
    01:51 Project Dependencies
    02:41 Mapping Annotations
    05:53 SessionFactory
    08:17 Save / Update / Delete - Basic CRUD
    10:33 HQL Queries
    13:33 JPA
    17:37 Criteria API
    22:22 Hibernate /JPA & Spring Boot
    24:11 Outro - What to learn next
    ► FOLLOW ME
    / marcobehler
    www.marcobehler.com
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 136

  • @equilibrium6577
    @equilibrium6577 ปีที่แล้ว +54

    You should've already had thousands of views! WTF?

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +14

      If you can have a chat with the TH-cam algorithm, I would appreciate it ;)

    • @equilibrium6577
      @equilibrium6577 ปีที่แล้ว +5

      @@MarcoCodes Thank you for the great content! I purchased your Spring course and I loved it! Unfortunately, I'm unable to buy a Maven one, as Russia got locked out from the whole world and Visa/Mastercard no longer work. No Marco, no Udemy, no Coursera😭 Hope pointless war ends soon...

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +4

      Thanks for the feedback, really great to hear! Yes, let's hope this pointless war ends soon, absolutely.

    • @Jod4light
      @Jod4light ปีที่แล้ว +4

      @@equilibrium6577 Thank you! I just found out that Marco sells courses with your message!

    • @equilibrium6577
      @equilibrium6577 ปีที่แล้ว

      @@Jod4light they are gooood!

  • @poorpanda9033
    @poorpanda9033 8 หลายเดือนก่อน +1

    So grateful that I found your channel. Amazing video, clear & concise !

  • @alBoomer19
    @alBoomer19 ปีที่แล้ว +1

    Excellent intro to JPA and Hibernate, thanks this was awesome.

  • @martindzeble
    @martindzeble วันที่ผ่านมา

    Other tutors should come and learn from you b'cos you made this concept soo simple to understand. Thank you a lot

  • @dezwujie
    @dezwujie 5 หลายเดือนก่อน +3

    I found your video by searching “hibernate crash course” and it was great! Just what I was looking for, especially the sections on JPA and Spring. Thanks!

  • @spiralspree
    @spiralspree 9 หลายเดือนก่อน +1

    best thing about this video is that it puts the knowledge into context of other apis and frameworks, so now I know where and what to look for if I need extra information.

  • @sebon11
    @sebon11 ปีที่แล้ว +1

    Extremely clear and great explanation, thank you!

  • @gabebraden915
    @gabebraden915 3 หลายเดือนก่อน +2

    This video is head & shoulders above the other Hibernate tutorials out there. Great job Marco!

  • @GuestUser-vf9qe
    @GuestUser-vf9qe 27 วันที่ผ่านมา

    Thank you, Marco, this crash course is awesome. And I'm about to become a student of your Confident Spring Pro course. It's really helpful.

  • @Llink4n
    @Llink4n ปีที่แล้ว +1

    This is really helpful. With good examples and best practices. Thank you

  • @tornike3755
    @tornike3755 ปีที่แล้ว +3

    Great content as always!

  • @vidya9587
    @vidya9587 11 หลายเดือนก่อน +1

    Putting all that information in such a short video is a skill !! Great job Marco

    • @MarcoCodes
      @MarcoCodes  11 หลายเดือนก่อน

      I appreciate that!

  • @RobsonCassianoSoftware
    @RobsonCassianoSoftware ปีที่แล้ว +21

    It's clear that you really care about delivering great content, thanks.

  • @vinayakmahajan6964
    @vinayakmahajan6964 11 หลายเดือนก่อน

    Thanks For Making it Simple and To the Point. Thanks Again.

  • @Yopajoe
    @Yopajoe ปีที่แล้ว +1

    Very good explanation and selecting key points of topic which lead to really good understanding of jpa and spring boot aspects. Thank you.

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Glad you liked it!

  • @hplatcuaemday
    @hplatcuaemday 3 หลายเดือนก่อน

    You explained very clearly, thank you for helping me in my journey of learning java

  • @1Backi
    @1Backi 11 หลายเดือนก่อน

    Was reading in to spring and decided to take a minute too understand its jpa features origin and differences between jpa and hibernate. Answered a lot of questions and contains good amount of easy to consume informations. :)

    • @MarcoCodes
      @MarcoCodes  11 หลายเดือนก่อน

      Great to hear!

  • @KolosBros
    @KolosBros ปีที่แล้ว +2

    Marco, You're doing awesome job!

  • @anugrah.singhal
    @anugrah.singhal ปีที่แล้ว +1

    Great Video.
    Love how the frustration is visible throughout :D

  • @douglasdotv
    @douglasdotv 8 หลายเดือนก่อน

    A very nice video that taught me a lot of things. Thank you.

  • @adrianstanci5122
    @adrianstanci5122 3 หลายเดือนก่อน

    Great video! I loved how everything was explained, it was super easy to digest. It helped me so much to refresh all my knowledge about this topic, in fact I think I have it way more clear now than when I studied it in college 😂

  • @returncode0000
    @returncode0000 ปีที่แล้ว +15

    I like the style of how fast this turtorial comes to the point and covers the essentials. How would the world look like if everyone would do such kind of high quality tutorials? 😄 Great teaching skills Marco, thumbs up 👍

  • @RicardoSilvaTripcall
    @RicardoSilvaTripcall 10 หลายเดือนก่อน

    Amazing content, Congrats !!!

  • @user-lc8wy7ck4p
    @user-lc8wy7ck4p ปีที่แล้ว

    Great video, thanks!

  • @eminsimsek2308
    @eminsimsek2308 ปีที่แล้ว +1

    very well explained. I hope your channel becomes more popular.

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Thanks. I hope so too :)

  • @Jod4light
    @Jod4light ปีที่แล้ว +1

    You deserve millions of subscribers and viewers, your contents quality is amazing

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +1

      Thank you for the kind words, really appreciated.

  • @fuadgafarov
    @fuadgafarov ปีที่แล้ว +1

    Thanks. Very clear explanation.

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Glad it was helpful!

  • @user-os6wp9gv9p
    @user-os6wp9gv9p 9 หลายเดือนก่อน

    This was amazing!! Currently i got my first job as software developer and my company mainly uses springboot and this video helped me clear a lot of thoughts, thanks

    • @MarcoCodes
      @MarcoCodes  9 หลายเดือนก่อน

      Congrats!

  • @ozanaydogan4625
    @ozanaydogan4625 3 หลายเดือนก่อน

    22:45 I have been looking for answers to these questions from Indian bros for 2 days, thank you for answering my questions in 1 minute. Thanks

  • @JorgeFerreira-dp9og
    @JorgeFerreira-dp9og ปีที่แล้ว +2

    I was looking for a quick overview of hibernate that we will cover this week, and this fit perfectly. I like the clarity and "to the point" , practical approach of your tutorial. If I see a course on Udemy by you, I will definetely buy it!

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Thanks! There won't be any Udemy courses by me, though :)

  • @jelen00711
    @jelen00711 ปีที่แล้ว +1

    this is really good video thank you :) thumbs up

  • @nazimesari6294
    @nazimesari6294 ปีที่แล้ว

    the best hibernate video

  • @ayuobmousa6589
    @ayuobmousa6589 ปีที่แล้ว

    awesome video Marco i like it

  • @user-kh5cc6zz2q
    @user-kh5cc6zz2q ปีที่แล้ว +1

    Thanks man!

  • @milanstojkovic2630
    @milanstojkovic2630 ปีที่แล้ว +1

    Nice and useful. Thanks

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +1

      Glad it was helpful!

  • @elvispontes4165
    @elvispontes4165 ปีที่แล้ว +1

    Thank you very much for sharing

  • @rajshreerai628
    @rajshreerai628 ปีที่แล้ว +1

    Awesome!

  • @adeshyaduvanshi2482
    @adeshyaduvanshi2482 ปีที่แล้ว

    wow..awesome dude

  • @Serencam
    @Serencam ปีที่แล้ว

    you are a King

  • @rajshreerai628
    @rajshreerai628 ปีที่แล้ว

    If all channels taught like Marco, we'd be working in Google rn.

  • @dventimihasura3034
    @dventimihasura3034 4 หลายเดือนก่อน

    LOL I love this guy.

  • @yaseenkhan9012
    @yaseenkhan9012 11 หลายเดือนก่อน

    i am a beginner but i got points like html speed of video is 1.5 nice way of explaing sir thank you for making video

  • @jona312312
    @jona312312 ปีที่แล้ว

    thank you

  • @rydmerlin
    @rydmerlin ปีที่แล้ว +1

    Your repository was a little light public interface CrudRepository extends Repository

  • @akulaganeshsantosh4584
    @akulaganeshsantosh4584 ปีที่แล้ว +1

    awesome

  • @hassanben_amar2495
    @hassanben_amar2495 ปีที่แล้ว

    I like you Marco, I like your way of sharing and teaching. I wish that you will see my comment ! Im a software engineer by the way

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Hi Hassan and thanks!

  • @karolinaparmas
    @karolinaparmas 9 หลายเดือนก่อน

    🎉 nice

  • @Muescha
    @Muescha ปีที่แล้ว +1

    i like to watch tutorials side by side with an running IDE - i have a wish: for every video episode i would like to have a starting Github Repo - (and maybe a result repo) - or and initial commit or branch and an final commit or branch to the repo - then i also can compare my repo with the final repo if i miss some setting while replay your steps in the IDE

    • @Muescha
      @Muescha ปีที่แล้ว

      i looked through your repos on github but can not find a repo with 'org.example.user` and a file `schema.sql`

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +2

      Your wish is already fulfilled: github.com/marcobehlerjetbrains/hibernate-tutorial.git . I just forgot to add the repo to the description, but usually all my videos come with the repo. Let me know if that helps.

    • @Muescha
      @Muescha ปีที่แล้ว

      @@MarcoCodes thanks a lot - i was not aware that you have an additional dedicated marcobehlerjetbrains account :) i searched in the wrong user space :)

  • @rallysac277
    @rallysac277 ปีที่แล้ว +1

    What about the newer version of the book "Java Persistence with Spring Data and Hibernate", do you recommend that one? Or did you specifically put in the old one because of quality reasons?
    (nevermind, the book I mentioned was released AFTER your video)

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Yup, released after my video but even the older version would do. Enjoy the journey!

  • @personsw
    @personsw ปีที่แล้ว

    Thanks a lot for this! Clear and concise you really helped me understand what's going on. Is 2nd edition book recommended, or will the 1st edition from 2007 be enough to start? (few € for older vs many € for 2nd)

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +1

      Wouldn't recommend the 1st edition anymore. There is even a 3rd edition out already, so I would go for either 3rd or 2nd.

  • @tysascode
    @tysascode 6 หลายเดือนก่อน

    You know this guy is experienced when hes gone through the curve of: Light mode, Dark mode, back to light mode. Thats where the gigachad devs sit

  • @mysocial
    @mysocial ปีที่แล้ว +2

    If you define the User class into the hibernate.cfg.xml class, why do you need the @Entity annotation ?

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      It's a good question. I.e. you could probably leave out @Entity specifying the class directly in hibernate.cfg.xml - however, in most real life applications you'll have some sort of package scan/component scan, and then you definitely need @Entity to make it work - as opposed to specifying every class manually. Give it a try and see what Hibernate does!

  • @danyalloyal8414
    @danyalloyal8414 10 หลายเดือนก่อน

    instead of the empty constructor you could make a NoArgsControctor annotation above classname

    • @MarcoCodes
      @MarcoCodes  10 หลายเดือนก่อน

      If you are using Lombok, yes - which I am however not using in this video.

  • @rogerzhang5993
    @rogerzhang5993 ปีที่แล้ว

    I love Java

  • @PhoenoxProduction
    @PhoenoxProduction ปีที่แล้ว

    So what will happen if you create an entity class and you forget the empty constructor ? Btw if we assume that you have a constructor with all parameters why hibernate cant manage to create an object and to save it successfully

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +1

      If I remember correctly, if you're missing the (implicit or explicit) no-arg constructor, you'll simply get an exception thrown, but you'll need to try it out :)
      As for your second question, I suppose there are a multitude of reasons, i.e. that afaik the reflections API doesn't easily work with constructors, that having super-long constructors for classes/tables with tons of fields is akward etc etc, but don't take it as the final say :D

  • @ehsanrezazadeh1
    @ehsanrezazadeh1 ปีที่แล้ว

    Thanks for ur excellent video! but do u use LIGHT THEME bro?

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      For videos, yes. For normal work,.dark theme.

  • @williamtlittle
    @williamtlittle หลายเดือนก่อน

    My java ee application uses an EntityManager throughout, so when I am writing unit tests I need to create an EntityManager configured to use a test database to give to my application code. I created a hibernate.cfg.xml file in src/test/resources. I have a problem though that my entities are not being scanned correctly. In the config file there is a packagesToScan property which lists the package where entities are in my application. However, those packages are in src/main/java, while my tests are in src/test/java. This is causing the problem that when I create a query with the name of my entity, I get an exception which says my entity is not mapped. How do I tell hibernate to scan a package in a different directory?

    • @MarcoCodes
      @MarcoCodes  7 วันที่ผ่านมา

      I unfortunately cannot do a proper remote-diagnosis. Hope you could work this out.

  • @tombrady7390
    @tombrady7390 ปีที่แล้ว

    thanks ryan gosling for teaching me hibernate

  • @Muescha
    @Muescha ปีที่แล้ว +1

    19:30 - Generated Sources User_
    They are not recognized by IntelliJ out of the box. I need to right tap at "target/generated-sources" node and select "Mark Directory as ..." / "Generated Sources Root" to be able to have an Import Option with the User_ class.
    But somehow this feels cheating if i have to setup something in the IDE after git checkout. I think this should be somehow in some settings files. i found some "howto" with a Gradle file. but this project is not using Gradle.
    How is the right way to setup the generated sources?

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว +1

      Have a look at the pom.xml file from the sample project. There's a "build-helper-maven-plugin" specified, which does add the sources automatically to your IntelliJ.

    • @Muescha
      @Muescha ปีที่แล้ว

      @@MarcoCodes but if i run a "normal" build "Build Project" in IntelliJ this add-source goal was not executed?

  • @josevsebastian2909
    @josevsebastian2909 ปีที่แล้ว

    hi. i'm trying to set up the hibernate meta model generation in my spring boot application.
    how do I generate the sources? jaxb-runtime doesn't seem to be wokring.
    PS. I'm new to java, so i'm not exactly knowledgeable in configuring pom.xml and all. Also, I'm using VS code.

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Hi Jose, it's unfortunately hard to tell without ...sitting at your desk/having your sources.

    • @josevsebastian2909
      @josevsebastian2909 ปีที่แล้ว

      @@MarcoCodes I know. But no worries. It seemed like I needed to reload vscode after putting the maven plugin. It's working now. 👍
      Just took four hours to figure that out.

  • @upn2772
    @upn2772 ปีที่แล้ว

    My googling tells me that JPA is a specification and that Hibernate is an implementation for that specification. That being said, I'm worried that I'll be confused if I read through the Java Persistence with Hibernate book when I go to work with JPA in for example Spring Boot. Is there no JPA specific book you could recommend?

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      No need to worry: 99% (oversimplified) of the time when you use JPA in a Spring Boot application, it's with Hibernate as the "persistence provider". And the book gives you a perfect foundation for both, the JPA spec + Hibernate - there is no such thing as "just a JPA book", because as you said, it's just a specification.

    • @WayManlyWay
      @WayManlyWay ปีที่แล้ว

      @@MarcoCodes Thank you for the quick reply. One thing I’d like to highlight is that the same author/authors are releasing a new book called “Java Persistence with Spring Data and Hibernate” listed on Amazon with a release date on the 14th of February 2023.
      I wonder if that will act as an upgrade/replacement for the book recommended in this video.
      I’m thinking of simply waiting for this new book.
      Any thoughts?
      My current situation is I’m doing a two year Java degree. I’m in my second year and I’m starting a Volvo internship in february where they use Java/Spring Boot.

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Two things: Working through the book will realistically take you months, so it's basically always better to have started yesterday :) Plus, Spring Data comes,essentially, on top of Hibernate/JPA and everything that is in the second edition will still be valid. I.e. I would start working through the book now, and then additionally do the Spring Data once it's released, as sort of a refresher + expansion of knowledge :)

  • @KevinSheppard
    @KevinSheppard ปีที่แล้ว

    Is it good practice/required to open and commit a transaction if you're just reading from the database?

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Long story, but short answer: If you don't explicitly open up the transaction yourself, your database will anyway open an implicit transaction. There are plenty of threads on this on stackoverflow, if you search around.

    • @KevinSheppard
      @KevinSheppard ปีที่แล้ว

      @@MarcoCodes Thank you so much! I really enjoy your content. I discovered you in this month's Java Annotated Monthly.

  • @mohangabhale5555
    @mohangabhale5555 ปีที่แล้ว

    Where can I get Hibernate Jar files for Ubuntu operating system.

    • @MarcoCodes
      @MarcoCodes  ปีที่แล้ว

      Unfortunately this question doesn't really make sense. What specifically are you trying to do?

    • @mohangabhale5555
      @mohangabhale5555 ปีที่แล้ว

      @@MarcoCodes i need Hibernate external jar files I want to add in eclipse... But I am using Java eclipse on Ubuntu ..

  • @Bang-_-Bang
    @Bang-_-Bang 7 หลายเดือนก่อน

    how to setup hibernate I am too confused there are too many error I am getting
    bruh please add setup at beginning

    • @MarcoCodes
      @MarcoCodes  7 หลายเดือนก่อน

      Check this out: docs.jboss.org/hibernate/orm/6.4/quickstart/html_single/

  • @tonisun4785
    @tonisun4785 ปีที่แล้ว

    ❤🧡💛💚💙💜🤎🖤🤍 Ich mag dich soooo viel

  • @hplatcuaemday
    @hplatcuaemday 3 หลายเดือนก่อน

    1:32 content: why use it

  • @minor12828
    @minor12828 5 หลายเดือนก่อน

    I can sense the level of hate Marco has for hibernate 😂😂😂.

    • @MarcoCodes
      @MarcoCodes  5 หลายเดือนก่อน

      Really no hate towards Hibernate, but would love to see more people understand "what" they are using :D

  • @marcovalentinoalvarado3290
    @marcovalentinoalvarado3290 5 หลายเดือนก่อน

    I'm also named Marco, I also like Java, I want to work in Java, I look like you but worse 🤣🤣🤣🤣🤣

  • @amol0328
    @amol0328 ปีที่แล้ว

    came here after wasting weeks on hibernate courses

  • @zedd0462
    @zedd0462 ปีที่แล้ว

    I respect you but this course is very lacking, i know the hibernate framework is complex, but usually when i see crash crouse or a youtube video it means i'm struggling with documentation, you can't just say "go read a book" when you reach important notes.
    This video is kind of useless.
    Thank you for your efforts tho.

  • @UnaiPerez-vf6fw
    @UnaiPerez-vf6fw 6 หลายเดือนก่อน

    Hi, very helpful video. I followed your tutorial but now I receive this error:
    org.hibernate.query.sqm.UnknownEntityException: Could not resolve root entity 'Usuario'.
    This is the query that I'm doing:
    Query query = session.createQuery("SELECT u FROM Usuario u", Usuario.class);
    entities = query.getResultList();
    And this is the entity in question:
    @Entity
    @Table(name = "Usuario")
    public abstract class Usuario
    I really have no idea of what is wrong, could you help me?

    • @MarcoCodes
      @MarcoCodes  6 หลายเดือนก่อน +1

      Try removing the "abstract" keyword

    • @UnaiPerez-vf6fw
      @UnaiPerez-vf6fw 6 หลายเดือนก่อน

      @@MarcoCodes Doesn't work either, seems to be something related to the mapping configuration, but I cannot find a solution. The NativeQuery works so I am using that at the moment. Thanks for the comment

  • @cypherliquid
    @cypherliquid ปีที่แล้ว

    Intellij paid version right?

  • @Andboldquates
    @Andboldquates ปีที่แล้ว

    thank you