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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:32:33+00:00 2026-05-15T08:32:33+00:00

Well, I have implemented a distinct query in hibernate. It returns me result. But,

  • 0

Well, I have implemented a distinct query in hibernate. It returns me result. But, while casting the fields are getting interchanged. So, it generates casting error. What should be the solution?

As an example, I do have database, “ProjectAssignment” that has three fields, aid, pid & userName. I want all distinct userName data from this table. I have applied query :

select distinct userName, aid, pid from ProjectAssignment

Whereas the ProjectAssignment.java file has the fields in sequence aid, pid & userName. Now, here the userName is first field in output. So, Casting is not getting possible.

Also, query :

select aid, pid, distinct userName from ProjectAssignment

is not working.

What is the proper query for the same ? Or what else the solution ?

The code is as below :

System Utilization Service Bean Method where I have to retrieve data :

public List<ProjectAssignment> getProjectAssignments() {
        projectAssignments = ProjectAssignmentHelper.getAllResources(); //Here comes the error
        return projectAssignments;
    }

ProjectAssignmentHelper from where I fetch Data :

package com.hibernate;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

public class ProjectAssignmentHelper {

    public static List<ProjectAssignment> getAllResources() {
        List<ProjectAssignment> projectMasters;

        Session session = HibernateUtil.getSessionFactory().openSession();
        Query query = session.createQuery("select distinct aid, pid, userName from ProjectAssignment");
        projectMasters = (List<ProjectAssignment>) query.list();
        session.close();

        return projectMasters;
    }
}

Hibernate Data Bean :

package com.hibernate;

public class ProjectAssignment  implements java.io.Serializable {

     private short aid;
     private String pid;
     private String userName;

    public ProjectAssignment() {
    }


    public ProjectAssignment(short aid) {
        this.aid = aid;
    }
    public ProjectAssignment(short aid, String pid, String userName) {
       this.aid = aid;
       this.pid = pid;
       this.userName = userName;
    }

    public short getAid() {
        return this.aid;
    }

    public void setAid(short aid) {
        this.aid = aid;
    }
    public String getPid() {
        return this.pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }
    public String getUserName() {
        return this.userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
}

Error :

For input string: “userName”

java.lang.NumberFormatException: For input string: "userName"
 at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
 at java.lang.Integer.parseInt(Integer.java:447)
 at java.lang.Integer.parseInt(Integer.java:497)
 at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:375)
 at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:195)
 at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
 at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
 at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
 at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
 at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
 at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
 at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
 at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
 at javax.faces.component.UICommand.getValue(UICommand.java:218)
 at org.primefaces.component.commandlink.CommandLinkRenderer.encodeMarkup(CommandLinkRenderer.java:113)
 at org.primefaces.component.commandlink.CommandLinkRenderer.encodeEnd(CommandLinkRenderer.java:54)
 at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
 at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70)
 at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:54)
 at org.primefaces.component.datatable.DataTableRenderer.encodeTable(DataTableRenderer.java:525)
 at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:407)
 at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:193)
 at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
 at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70)
 at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:54)
 at org.primefaces.component.tabview.TabViewRenderer.encodeContents(TabViewRenderer.java:198)
 at org.primefaces.component.tabview.TabViewRenderer.encodeMarkup(TabViewRenderer.java:130)
 at org.primefaces.component.tabview.TabViewRenderer.encodeEnd(TabViewRenderer.java:48)
 at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
 at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
 at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
 at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
 at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
 at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
 at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
 at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
 at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
 at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:802)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:664)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:497)
 at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:468)
 at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:364)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:314)
 at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:783)
 at org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java from :59)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:406)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
 at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
 at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
 at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
 at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
 at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
 at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
 at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
 at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
 at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
 at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
 at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
 at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
 at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
 at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
 at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
 at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
 at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
 at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
 at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
 at java.lang.Thread.run(Thread.java:619)
  • 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-15T08:32:33+00:00Added an answer on May 15, 2026 at 8:32 am

    Why do you want to use HQL?

    The idea of Hibernate is to work with entities and not with tables. Ideally, you would load the entities and iterate through them getting the fields you want.

    I would suggest you to use Hibernate Criteria and Criterion to that query.

    Criteria crit = session.createCriteria(ProjectAssignment.class);
    List projectAssignments = crit.list();
    

    And then iterate through the list getting the fields you want.

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

Sidebar

Related Questions

Well i have implemented my own NFS server and everything is working good but
I have implemented lucene for my application and it works very well unless you
I have implemented a simple chat console app and it worked well. When i
Trying to use federated authentication with AppEngine. I have implemented the authenication part but
I have implemented OOP in my lua environment but it doesnt seem to be
I have a database that I have implemented Hibernate integration with. I was wondering
I have implemented repository pattern and it works pretty well. public interface IServiceRepository {
I have implemented Authlogic to my app, but I am confused about the sense
So I have implemented salts and IVs, but the decryption is now a bit
I have implemented TCp concurrent server and client in c using threads as well

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.