Hibernate / Hibernate 7 Basics Interview Questions
What is the @Filter and auto-enabled filters feature in Hibernate 7?
Hibernate Filters are parameterised WHERE clause fragments applied to a Session. Hibernate 7 adds auto-enabled filters that activate automatically without explicit session.enableFilter() calls.
@FilterDef( name="activeFilter", parameters=@ParamDef(name="isActive", type=Boolean.class) ) @Filter(name="activeFilter", condition="is_active = :isActive") @Entity public class Product { @Id private Long id; private String name; private boolean isActive; } // Enable for this session: session.enableFilter("activeFilter").setParameter("isActive", true); // All Product queries now silently include: AND is_active = true List<Product> active = session.createQuery("FROM Product", Product.class).getResultList(); session.disableFilter("activeFilter"); // HIBERNATE 7: auto-enabled filter for multi-tenancy @FilterDef( name="tenantFilter", parameters=@ParamDef(name="tenantId", type=Long.class), autoEnabled=true // no session.enableFilter() needed! ) @Filter(name="tenantFilter", condition="tenant_id = :tenantId") @Entity public class Order { ... } // FilterDefContributor SPI resolves tenantId from ThreadLocal automatically
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...
