Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7717971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:02:44+00:00 2026-06-01T03:02:44+00:00

I need to join two JPA entities on a property when there is no

  • 0

I need to join two JPA entities on a property when there is no FK/PK relation between the two.
I am using Hibernate and can use HQL query like this

 select foo, bar from FooEntity as foo, BarEntity as bar
 where  foo.someothercol = 'foo' and foo.somecol = bar.somecol

However, I want to avoid dependency on Hibernate and use EntityManager instead.
Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:02:45+00:00Added an answer on June 1, 2026 at 3:02 am

    Your query is valid JPQL and does not use Hibernate specific functionality (just space between bar and from is missing). In JPA 2.0 specification (4.4.5 Joins) this is explained with following words:

    An inner join may be implicitly specified by the use of a cartesian
    product in the FROM clause and a join condition in the WHERE clause.
    In the absence of a join condition, this reduces to the cartesian
    product.

    The main use case for this generalized style of join is when
    a join condition does not involve a foreign key relationship that is
    mapped to an entity relationship. Example: SELECT c FROM Customer c, Employee e WHERE c.hatsize = e.shoesize

    Main difference to your query is that your select contains two types of entities. Result of query is List of Object[]. Order of elements in array is same as in select
    statement. Following works in your case:

    String query =
        "select foo, bar from  FooEntity as foo, BarEntity as bar "+
        "where  foo.someothercol = 'foo' and foo.somecol = bar.somecol";
    List<Object[]> results = em.createQuery(query).getResultList();
    
    for (Object[] fooAndBar: results) {
        FooEntity foo = (FooEntity) fooAndBar[0];
        BarEntity bar = (BarEntity) fooAndBar[1];
        //do something with foo and bar
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to run a JOIN query on a solr index. I've got two
I use JPA inheritance with JOIN strategy (JPA2/Hibernate). I have an abstract general Event
When I need to join two strings I use String.Format (or StringBuilder if it
Is it possible to join two classes without specified mapping between them (using Criteria
I need to join two XML documents using LINQ and I'm not sure where
I need to join two tables from different MySQL (PHP) connection strings and different
I need to join two tables based on columns with different types. The first
I need to join the following two tables table_A id userId name score game
How would I join two lines using awk or sed? I have data that
For reasons beyond my control, I need to join two tables and I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.