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

  • Home
  • SEARCH
  • 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 7792625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:14:33+00:00 2026-06-01T22:14:33+00:00

Good morning. I have been looking all over trying to answer this question. If

  • 0

Good morning. I have been looking all over trying to answer this question.

If you have a table that has foreign keys to another table, and you want results from both tables, using basic sql you would do an inner join on the foreign key and you would get all the resulting information that you requested. When you generate your JPA entities on your foreign keys you get a @oneToone annotation, @oneToMany, @ManyToMany, @ManyToOne, etc over your foreign key columns. I have @oneToMany over the foreign keys and a corresponding @ManyToOne over the primary key in the related table column I also have a @joinedON annotation over the correct column… I also have a basic named query that will select everything from the first table. Will I need to do a join to get the information from both tables like I would need to do in basic sql? Or will the fact that I have those annotations pull those records back for me? To be clear if I have table A which is related to Table B based on a foreign key relationship and I want the records from both tables I would join table A to B based on the foreign key or

Select * From A inner Join B on A.column2 = B.column1

Or other some-such non-sense (Pardon my sql if it is not exactly correct, but you get the idea)…
That query would have selected all column froms A and B where those two selected column…
Here is my named query that I am using….

@NamedQuery(name="getQuickLaunch", query = "SELECT q FROM QuickLaunch q")

This is how I am calling that in my stateless session bean…

try
    {
        System.out.println("testing 1..2..3");
        listQL = emf.createNamedQuery("getQuickLaunch").getResultList();
        System.out.println("What is the size of this list: number "+listQL.size());
        qLaunchArr = listQL.toArray(new QuickLaunch[listQL.size()]);            

    }

Now that call returns all the columns of table A, but it lack’s the column’s of table B. My first instinct would be to change the query to join the two tables… But that kind of makes me think what is the point of using JPA then if I am just writing the same queries that I would be writing anyway, just in a different place. Plus, I don’t want to overlook something simple. So what say you stack overflow enthusiasts? How does one get back all the data of joined query using JPA?

  • 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-01T22:14:35+00:00Added an answer on June 1, 2026 at 10:14 pm

    Suppose you have a Person entity with a OneToMany association to the Contact entity.

    When you get a Person from the entityManager, calling any method on its collection of contacts will lazily load the list of contacts of that person:

    person.getContacts().size();
    // triggers a query select * from contact c where c.personId = ?
    

    If you want to use a single query to load a person and all its contacts, you need a fetch in the SQL query:

    select p from Person p 
    left join fetch p.contacts
    where ...
    

    You can also mark the association itself as eager-loaded, using @OneToMany(lazy = false), but then every time a person is loaded (vie em.find() or any query), its contacts will also be loaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning, I have a SharePoint site that I've been trying to fix up
Good morning I'm trying to get a table row (TR) that must have one
Good morning. I've been having this issue for some days and have been lokking
Good morning all, I'm sure this is a gimme, but I have no idea
Good Morning All, I have loaded over 1,300 blurbs into my client's database with
Good Morning All! I have been developing a project for some time in which
Good Morning , I have been trying to make a dynamic message box on
Good Morning Stack OverFlow enthusiasts. I have been having an issue that I am
I have an issue that's been bugging me this morning. I'm building an ASP.NET
Good morning I have been running a few tests over the past couple of

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.