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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:15:29+00:00 2026-05-16T21:15:29+00:00

I thought I know how to use JOIN in JPQL but apparently not. Can

  • 0

I thought I know how to use JOIN in JPQL but apparently not. Can anyone help me?

select b.fname, b.lname from Users b JOIN Groups c where c.groupName = :groupName

This give me Exception

org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query
Internal Exception: org.eclipse.persistence.internal.libraries.antlr.runtime.EarlyExitException

Users have a OneToMany relationship with Groups.

Users.java

@Entity
public class Users implements Serializable{

    @OneToMany(mappedBy="user", cascade=CascadeType.ALL)
    List<Groups> groups = null;
}

Groups.java

@Entity
public class Groups implements Serializable {
    @ManyToOne
    @JoinColumn(name="USERID")
    private Users user;
}

My second question is let say this query return a unique result, then if I do

String temp = (String) em.createNamedQuery("***")
    .setParameter("groupName", groupName)
    .getSingleResult();

*** represent the query name above. So does fname and lname concatenated together inside temp or I get a List<String> back?

  • 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-05-16T21:15:29+00:00Added an answer on May 16, 2026 at 9:15 pm

    Join on one-to-many relation in JPQL looks as follows:

    select b.fname, b.lname from Users b JOIN b.groups c where c.groupName = :groupName 
    

    When several properties are specified in select clause, result is returned as Object[]:

    Object[] temp = (Object[]) em.createNamedQuery("...")
        .setParameter("groupName", groupName)
        .getSingleResult(); 
    String fname = (String) temp[0];
    String lname = (String) temp[1];
    

    By the way, why your entities are named in plural form, it’s confusing. If you want to have table names in plural, you may use @Table to specify the table name for the entity explicitly, so it doesn’t interfere with reserved words:

    @Entity @Table(name = "Users")     
    public class User implements Serializable { ... } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know, I would have thought the answer was obviously no as well, but
I know Windows has SMTP capabilities under IIS, but I thought a basic SMTP
I know this one is going to be a long-shot, but I thought I'd
I think I already know the answer to this but thought I would ask
I know .net supports base64 encoding of byte arrays. But i thought that i
So I know there is a few templating engines out there, but I thought
I don't claim to know anything about svn, but I thought I understood how
$sql = SELECT messages.text, users.name FROM messages INNER JOIN users ON messages.user_id=users.id ORDER BY
I know WPF is more complex an flexible so could be thought to do
I know WF designer has re-hosting capability. Since it's WPF-based, I thought it might

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.