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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:54:07+00:00 2026-06-03T09:54:07+00:00

I am using ireport-4.5.0,spring3.0.5RELEASE,jpa2 . I have an entity class named as User and

  • 0

I am using ireport-4.5.0,spring3.0.5RELEASE,jpa2. I have an entity class named as User and having the attributes as follow
userId,
userName,
password.I

Designed the jrxml by giving the fields as these three attributes names.If i give the jpa Query as From USer then it is working fine and giving the result. But i want the distinct values of userName(userName column allows duplicate values also)so i have given the jpaQuery as

SELECT userId,DISTINCT(userName),password FROM User 

Then i am not getting the result.What is the problem with the query.

Hi here i am giving the code i am using

public User getUsers() throws Exception{
 Query uQuery = entityManager.createQuery("SELECT u.userId,u.userName,u.password FROM User u GROUP BY u.userId,u.userName,u.password");
       List <User>listOfUsers = uQuery.getResultList();
       if (listOfUsers == null) {
           throw new ResourceNotFound();
        }
       for (Iterator iterator = listOfUsers.iterator(); iterator.hasNext();) {
            User userList = (User)iterator.next();

        }

       return userList;

Here i am getting the ClassCastException:java.lang.String cannot be cast to User.It is showing this exception in the for loop statement.I am new to JPA.Can you please explain how to iterate that list of objects.

  • 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-03T09:54:09+00:00Added an answer on June 3, 2026 at 9:54 am

    You cannot put DISTINCT on a single column in JPQL or SQL.

    You most likely need to use a group by,

    SELECT u.userId,u.userName,u.password FROM User u group by u.userId, u.userName, u.password

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

Sidebar

Related Questions

I am using IReport 4.5.0 and I have this report having a Crosstab. This
I am having a problem in using a iReport. I have a general master
Using ireport I know how to make input controls but I have one issue
I am using JasperReport's iReport 4.5.0 designer to build my report. I am having
I am designing an invoice using iReport but i am having a problem with
I have design report using iReport . In this report I have one custom
I have made a Jasper line chart using ireport. Now I want to convert
Hello I'm completely new to using Jaspersoft iReport Designer. I want to have a
I have designed jasper report using iReport version (4.7.1). Through iReport it works fine.
I'm using iReport 2.0.2 . I have a problem with formatting numeric data after

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.