Hibernate / Hibernate 7 Basics Interview Questions
What is HQL (Hibernate Query Language) in Hibernate 7?
HQL is Hibernate's object-oriented query language operating on entity objects rather than tables. Hibernate 7 adds new HQL functions including regexp, JSON/XML manipulation, and set-returning functions.
// Basic HQL - uses entity class name, not table name: List<Product> all = session .createQuery("FROM Product", Product.class) .getResultList(); // WHERE with named parameter: List<Product> active = session .createQuery("FROM Product WHERE status = :status", Product.class) .setParameter("status", ProductStatus.ACTIVE) .getResultList(); // Constructor expression (DTO projection): List<ProductSummary> s = session .createQuery( "SELECT new com.example.ProductSummary(p.id, p.name, p.price) " + "FROM Product p WHERE p.price < :max", ProductSummary.class) .setParameter("max", new BigDecimal("100")) .getResultList(); // JOIN on association fields: List<Order> orders = session .createQuery("FROM Order o JOIN o.customer c WHERE c.email = :email", Order.class) .setParameter("email", "alice@example.com") .getResultList(); // Pagination: List<Product> page = session .createQuery("FROM Product ORDER BY createdAt DESC", Product.class) .setFirstResult(0).setMaxResults(20).getResultList(); // Hibernate 7 new: regexp operator List<Product> matched = session .createQuery("FROM Product WHERE name regexp :pattern", Product.class) .setParameter("pattern", "^(Laptop|Phone)") .getResultList();
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...
