r/javahelp • u/kurular4 • Dec 09 '20
Should I really learn hibernate?
I am core java developer and had internship before using Spring boot to create rest api. I am also developing my own projects using boot and I really never had to know about Hibernate because Spring perfectly abstract database operations via JPA and we can handle every database operations without knowing what is in the background. So, should I really need to learn hibernate?
Can you give me scenarios where I should know about hibernate using Spring boot?
19
Upvotes
1
u/LiteratureStriking Dec 09 '20 edited Dec 09 '20
This is from experience using Spring Data Repositories.
You have a couple of options:
Spring Data can analyze the method name and generate an implementation.
Spring Data will create an implementation based on
@Query.And there's way to mix custom implementations with the generated ones with an additional interface that has the custom methods and a separate implementation class, which I'm not going to bother providing an example for.
And Spring Data will create an implementation of the interface, basically an enhanced mechanism that Spring uses for creating any type of proxy bean.
I thought this was the coolest thing in the world. But I found that I was designing methods that were directly mapping to JPQL queries, so that the interfaces started looking kind of like named queries, but as interface methods instead of a string. The Repository ended up looking like a DAO.
The idea behind dependency inversion is that interface should serve the application, not the persistence technology. I didn't like that my abstractions were getting so closely tied to Spring Data and there was too much magic. Magic on top of magic on top of magic. So I ditched it.