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 8997213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:51:29+00:00 2026-06-15T23:51:29+00:00

I have two tables: Customers and Commands, it’s a @OneToMany relation from Client to

  • 0

I have two tables: Customers and Commands, it’s a @OneToMany relation from Client to Commands, one client have many Commands.
the table commands contain : idCommand, date, nameCommande, idCustomer.
the table customers contain: idCustomer, nameClient, email.
All the JPA and EJB are set up and I can easily get a list of Commands or Clients using an HQL query in a managed bean and list them in a JSP using this code.

 public List<Commande> selectAllCommandes() {
    List<Commande> commandes = em.createQuery("select c from Commande c").getResultList();
      return commandes;
}
 public List<Customer> selectAllCustomers() {
    List<Customer> customers = em.createQuery("select cu from Customer cu").getResultList();
    return customers;
}

How do I join the two tables with the idCustomer column in a way to show the name of client instead his id? I’ve used this HQL query

SELECT c.date, c.name Commande, cu.nameClient FROM Commande AS c, Customer AS cu WHERE cu.idCustomer = c.idCustomer

But I have no idea about the List<> type that I need to use to get the result/

  • 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-15T23:51:30+00:00Added an answer on June 15, 2026 at 11:51 pm

    If you map the reverse relation in the Commande entity …

    public class Commande {
        ...
    
        @ManyToOne(mappedBy="commande")
        private Client client;
    
        // getter and setter ...
    }
    

    (Here, mappedBy is getting the name of the @OneToMany property set up at the
    other side of the relationship)

    Then after executing your query SELECT c FROM Commande c you would get a list of Commande objects, and for each one of them you could get the name of the client using: thisCommande.getClient().getName().

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

Sidebar

Related Questions

I have two tables one with ID and NAME table 1 ID | NAME
Using PHP / MySQL I have two tables one is customers the other is
I have two tables Orders table and customers table, both have customerid as common
Let's say I have two tables one called Customers and one called CustomerAddresses. Then
I have two tables, customers and users. In the customers table, I have a
I am using PHP and MySQL. I have two tables, one for customers, and
Ok, so I have two tables in MySQL. One table holds customer information, the
I have two tables, customers and bank accounts, with a many-to-many relationship (each user
I have two tables in a 2010 Access Database. One for Customers and One
I have two tables whichs relation is expressed in a third n:m table. Lets

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.