Question

I get following error message when I try to load specific entities to my JSP form. This occurs when I try to load entities which types are "USER". So here's the error message:

WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.IllegalArgumentException: Can not set java.lang.String field com.mysite.bookingmeeting.user.UserProfile.userName to java.lang.Long
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
    at java.lang.reflect.Field.get(Field.java:372)
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
    at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
    at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:86)
    at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
    at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:184)
    at org.hibernate.engine.EntityUniqueKey.generateHashCode(EntityUniqueKey.java:63)
    at org.hibernate.engine.EntityUniqueKey.<init>(EntityUniqueKey.java:44)
    at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:596)
    at org.hibernate.type.EntityType.resolve(EntityType.java:382)
    at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
    at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
    at org.hibernate.loader.Loader.doQuery(Loader.java:729)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    at org.hibernate.loader.Loader.doList(Loader.java:2220)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    at org.hibernate.loader.Loader.list(Loader.java:2099)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
    at com.mysite.bookingmeeting.dao.implementation.UserProfileDaoImpl.findAllUsers(UserProfileDaoImpl.java:47)
    at org.apache.jsp.admin.ManageUsers_jsp._jspService(ManageUsers_jsp.java:133)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:328)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

According to this error message the problem lies in at com.mysite.bookingmeeting.dao.implementation.UserProfileDaoImpl.findAllUsers(UserProfileDaoImpl.java:47) and at org.apache.jsp.admin.ManageUsers_jsp._jspService(ManageUsers_jsp.java:133). I have checked those codes in those specific pages and they worked before fine but for some reasons now it won't work.

The code for method findAllUsers() of UserProfileDaoImpl() class is following:

@Override
    public Collection<UserProfile> findAllUsers() {
        EntityManager em = getEntityManager();
        Query q = em.createQuery("SELECT u FROM UserProfile u WHERE u.userType = 'USER'");
        List<UserProfile> results;
        results = q.getResultList();
        return results;
    }

And code for ManageUsers.jsp is following:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Manage Users</title>
    </head>
    <body>
        <h2>Create User</h2>
        <%@include file="../WEB-INF/jspf/createUser.jspf" %>
        <h2>Delete Users</h2>
        <%@include file="../WEB-INF/jspf/DeleteUserForm.jspf" %>
    </body>
</html>

I have tested above file without DeleteUserForm.jspf and it works well with no problems, so the main cause is DeleteUserForm.jsp and here the code of this form is following:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.Collection"%>
<%@page import="com.mysite.bookingmeeting.user.UserProfile"%>
<%@page import="com.mysite.bookingmeeting.dao.implementation.UserProfileDaoImpl"%>
<%@page import="com.mysite.bookingmeeting.dao.UserProfileDao"%>
<%
    UserProfileDao userProfiles = new UserProfileDaoImpl();
    Collection<UserProfile> allUsers = userProfiles.findAllUsers();

    session.setAttribute("users", allUsers);
%>
<%@ page pageEncoding="UTF-8" %>
<form name="deleteUser" action="DeleteUserServlet">
    <table border="0">
        <tbody>
            <tr>
                <td>User Name: </td>
                <td><select name="deleteUsers" multiple="multiple">
                        <c:forEach var="users" items="${users}">
                            <option value='<c:out value="${users.getId()}"/>'>
                                <c:out value="${users.firstName}"/> 
                                <c:out value="${users.lastName}"/>
                            </option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Delete Users" /></td>
            </tr>
        </tbody>
    </table>
</form>

This code also worked before but now its not working. Any help is really appreciated.

Was it helpful?

Solution

I solved the problem and I found out that I tried to set String type variable to UserProfile type variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top