Hibernate / Hibernate 7 Basics Interview Questions
What is the Session in Hibernate 7 and what are its core CRUD operations?
The Session is Hibernate's primary interface for database operations. It represents a unit of work and maintains the first-level cache. Key API changes in Hibernate 7:
| Old method (removed) | Hibernate 7 replacement |
|---|---|
| session.save(entity) | session.persist(entity) |
| session.get(Class,id) | session.find(Class,id) |
| session.delete(entity) | session.remove(entity) |
| session.update(entity) | session.merge(entity) |
| session.saveOrUpdate(entity) | session.merge(entity) |
session.beginTransaction(); // CREATE Product p = new Product("Book", new BigDecimal("19.99")); session.persist(p); // replaces save() // READ: returns null if not found Product found = session.find(Product.class, 1L); // replaces get() // READ lazy proxy Product ref = session.getReference(Product.class, 1L); // UPDATE: automatic dirty checking - no explicit call needed found.setPrice(new BigDecimal("24.99")); // DELETE session.remove(found); // replaces delete() // MERGE: integrate detached state Product copy = session.merge(detached); session.getTransaction().commit();
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
