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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:55:41+00:00 2026-06-17T10:55:41+00:00

I am using Spring 3, Hibernate 4 and JSF 2.0 and am trying to

  • 0

I am using Spring 3, Hibernate 4 and JSF 2.0 and am trying to do primefaces autocomplete.

I have the following in DAO class to get values from Oracle function

@Override
    public List<EmployeeDetail> getEmployeeDetails(String employeeNumber) {

        List query = (List)entityManager.createNamedQuery("getEmp")
                .setParameter("empNumber", employeeNumber)
                .getSingleResult();

        return query;

    }

Converter class

public EmployeeNameConverter(

            List<EmployeeDetail> employeeDB, EmployeeDetailService instance,
                    String employeeNumber) {
                if (employeeDetailService == null) {
                    employeeDetailService = instance;
                }
                if (param == null) {
                    param = employeeNumber;
                }
                this.employeeDB = employeeDB;
            }

@Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1,
            String submittedValue) {
        if (submittedValue.trim().equals("")) {
            return null;
        } else {
            try {
                // int number = Integer.parseInt(submittedValue);
                employeeDB = getEmployeeDetailService().getEmployeeDetails(param);
                for (EmployeeDetail emp : employeeDB) {
                    if (emp.getEmployeeNumber() == submittedValue) {
                        return emp;
                    }
                }

            } catch (NumberFormatException exception) {
                throw new ConverterException(new FacesMessage(
                        FacesMessage.SEVERITY_ERROR, "Conversion Error",
                        "Not a valid employee"));
            }
        }

In my Managedbean

I have complete method where I am passing employeeDetailService to my converter class.

public List<EmployeeDetail> complete(String query) {
        List<EmployeeDetail> suggestions;
        suggestions = new ArrayList<EmployeeDetail>();
        try {
            employee =  (List<EmployeeDetail>) new EmployeeNameConverter(
                    employeeList, employeeDetailService, query);

            for (EmployeeDetail p : employee) {
                if (p.getEmployeeNumber().startsWith(query))
                    suggestions.add(p);
            }
        } catch (Exception e) {
            System.out.println("exc " + e.getMessage());
            e.printStackTrace();
        }

        return suggestions;
    }

JSF Code

<p:autoComplete value="#{empMB.selectedEmployee}"
                            id="basicPojo" minQueryLength="6" 
                            completeMethod="#{empMB.complete}" var="p"
                            itemLabel="#{p.employeeNumber}" 
                            itemValue="#{p}" converter="#{p.employee}"
                            forceSelection="true" />

When I type in characters I am getting exception

EmployeeNameConverter cannot be cast to java.util.List
java.lang.ClassCastException: net.test.util.EmployeeNameConverter cannot be cast to java.util.List

How can I resolve this? Is this the correct approach or could someone kindly suggest better approach in achieving the same?

Update 1

@Override
    public List<EmployeeDetail> getEmployeeDetails(String employeeNumber) {

        List query = (List)entityManager.createNamedQuery("getEmp")
                .setParameter("empNumber", employeeNumber)
                .getSingleResult();

        return query;

    }

Exception

net.test.entity.EmployeeDetail cannot be cast to java.util.List
java.lang.ClassCastException: net.test.entity.EmployeeDetail cannot be cast to java.util.List
    at net.test.dao.EmployeeDetailDAOImpl.getEmployeeDetails(EmployeeDetailDAOImpl.java:36)

and exception line is

List query = (List)entityManager.createNamedQuery("getEmp")
                    .setParameter("empNumber", employeeNumber)
                    .getSingleResult();
  • 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-17T10:55:43+00:00Added an answer on June 17, 2026 at 10:55 am

    There are two main issues apparent here

    1. You’re attempting to instantiate and manage a JSF converter instance by hand. Don’t do this. The converter is a construct designed for use by the JSF context only. It’s not the job of you the developer to call new or supply constructor arguments to the converter class. Implement a simple converter per this example and configure on the <p:autoComplete/>

      From your comments, the reason you’ve taken to managing the converter by hand is to be able to access your DAO layer. As a workaround, you can add @ManagedBean to your converter and JSF will treat is as a managed bean and a converter. Being a managed bean, you’ll now be able to inject your DAO resource into it. This is not best practice, but only a workaround. This limitation on converters will be removed in JSF2.2 though :).

    2. While manipulating the converter, you’re attempting to treat it like a regular POJO and trying to cast it into several incompatible types as a result

       employee = (List<EmployeeDetail>) new EmployeeNameConverter( employeeList, employeeDetailService, query); //EmployeeNameConverter !instanceof EmployeeDetail
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I'm using Spring with Hibernate as a JPA provider and are trying to get
I am project I will be using following tech. JSF 2.0, Hibernate, Spring, jBPM,
I am using Spring + Hibernate, and I will have a HTML from that
I'm working in a Java EE web application using Hibernate, Spring, JSF and Primefaces.
i am using jsf 2,hibernate 4.1.4,spring 3.1,oracle 11g and maven 3. but it can
i am using spring 3 , JSF 2 , MYSQL , Hibernate , and
I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate
I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate

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.