How to search JPA entities by referenced entity's id without additional SQL queries issued?

Solution Verified - Updated -

Issue

There is an entity named "Foo" containing a reference to another entity (let's name it "Bar") in a many-to-one relationship. Is it possible in JPA to search for all Foos referencing a specific Bar so that only one SQL query would be issued to the database?

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.