If you are building Java apps with ORM and persistence you have landed in the ring with JPA and Hibernate. One is a specification that tries to keep everyone civil and portable. The other is a full featured implementation that throws glitter and performance knobs at you when you are feeling adventurous.
JPA is the standard API for object relational mapping in Java. It gives you annotations, the EntityManager API and a common mental model you can carry between providers. That means your code can move from one vendor to another with less drama and fewer tears. It is especially handy in teams where portability and predictable behavior matter more than heroics.
Hibernate implements JPA and then adds a set of extras. Think HQL, advanced caching strategies like second level cache, support for custom types, automatic schema generation tools and a bunch of integration utilities. If you want deeper control for performance tuning or a feature not in the spec you can reach for Hibernate. That control comes with the usual risk of vendor specific behavior, so please measure before you fall in love.
Use the JPA API for everyday CRUD and only drop to Hibernate specific code when you need to. The relationship is very simple to express in code. No dark magic required.
EntityManager em = getEntityManager()
Session session = em.unwrap(Session.class)
Those two lines show the difference between the standard API and the concrete implementation. Use EntityManager for most operations and unwrap to Session when you need HQL or specific features.
Start with JPA and Hibernate as the provider. Use Spring Data JPA to speed up common repository work. Only invoke Hibernate specific APIs for profiling or features not covered by the spec. Learn the standard API first since that knowledge moves between providers. Then learn Hibernate specifics when you need to tune or reach beyond the spec.
If you want predictability and portability pick JPA. If you want power and are okay with some vendor specific wiring pick Hibernate. If you work in a shop with a one true provider policy then you already know what you must do. Otherwise try both locally run benchmarks and measure actual queries before you cowboy your way into production.
Now go write fewer N plus one queries and enjoy the fleeting thrill of a fast database call.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.