Непредвиденная ошибка illegalargumentexception id to load is required for loading

When I try to access the findById it is showing the following: IllegalArgumentException "id to load is required for loading" Here's my code: package controllers; import play.*; import play.mvc.*;

When I try to access the findById it is showing the following:

IllegalArgumentException "id to load is required for loading"

Here’s my code:

package controllers;
import play.*;
import play.mvc.*;
import java.util.*;
import models.*;

public class Application extends Controller {

    public static void index() {

       render();
    }
    public static void saveUser(String name)
    {
        User1 user =new User1(name);
        String res = "";
        if( user.save()!=null){
            res="Stored Successfully";
        }
        else{
            res="Failed to store";
        }
        render(res);
    }
    public static void showUser(Long id)
    {
       User1 user=  User1.findById(id);
       render(user);
    }

}

and below is my routes file i don’t understand why the error is coming and illegal argument exception.
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET     /                                       Application.index

# Ignore favicon requests
GET     /favicon.ico                            404

# Map static resources from the /app/public folder to the /public path
GET     /public/                                staticDir:public

# Catch all
*       /{controller}/{action}                  {controller}.{action}

asked May 23, 2015 at 17:39

Ravi 's user avatar

Ravi Ravi

211 gold badge1 silver badge4 bronze badges

4

IllegalArgumentException is thrown because the id is null. Make sure you pass correct value with the request. Mapping the controller method in routes file as follows would prevent from passing null:

GET /user/{id} Aplication.showUser

answered May 23, 2015 at 18:51

Mon Calamari's user avatar

Mon CalamariMon Calamari

4,4033 gold badges25 silver badges44 bronze badges

The value of id variable that you pass to User1.findById is something unacceptable.

Maybe it’s a negative number. Read documentation to User1.findById to find requirements to the id variable.

Try this code to check the value of id before calling findById(id):

    public static void showUser(Long id)
    {
       System.out.println("Application,showUser(id = " + id + " );"
       User1 user=  User1.findById(id);
       render(user);
    }

answered May 23, 2015 at 17:48

Nick Volynkin's user avatar

Nick VolynkinNick Volynkin

13.6k6 gold badges42 silver badges66 bronze badges

0

View unanswered posts | View active topics

Author Message

Post subject: id to load is required for loading — Error

PostPosted: Sun Jan 15, 2006 10:11 pm 

Newbie



Joined: Sun Jan 15, 2006 8:26 pm
Posts: 9

Please help:

Hibernate version:3.0

Name and version of the database you are using :oracle 9i

java.lang.IllegalArgumentException: id to load is required for loading

at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:51)

at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:33)

at org.hibernate.impl.SessionImpl.get(SessionImpl.java:618)

at org.hibernate.impl.SessionImpl.get(SessionImpl.java:614)

at com.dcf.dataAccess.FLunearnedincomesummaryDALC.getProfileByPrimaryKey(FLunearnedincomesummaryDALC.java:105)

at com.dcf.struts.action.ScrFLUnEarnedIncomeSummaryAction.init(ScrFLUnEarnedIncomeSummaryAction.java:327)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)

at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)

at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)

at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)

at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Thread.java:534)

com.dcf.utils.AccessException

at com.dcf.dataAccess.FLunearnedincomesummaryDALC.getProfileByPrimaryKey(FLunearnedincomesummaryDALC.java:112)

at com.dcf.struts.action.ScrFLUnEarnedIncomeSummaryAction.init(ScrFLUnEarnedIncomeSummaryAction.java:327)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)

at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)

at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)

at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)

at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

at java.lang.Thread.run(Thread.java:534)

Top

Profile  

tenwit

Post subject:

PostPosted: Sun Jan 15, 2006 10:20 pm 

Expert
Expert



Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008

You’re passing null to Session().get(). You can’t get null.

Top

Profile  

thozhan_munus

Post subject:

PostPosted: Sun Jan 15, 2006 11:02 pm 



Joined: Sun Jan 15, 2006 8:26 pm
Posts: 9

This error comes only when we use

the LOADRUNNER tool. Under normal conditions

everything works fine.


_________________
Ramesh

Top

Profile  

tenwit

Post subject:

PostPosted: Sun Jan 15, 2006 11:46 pm 

Expert
Expert



Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008

I presume that that’s an Hibernate tool. Perhaps you could ask your question over on the Tools forum.

Top

Profile  

max

Post subject:

PostPosted: Mon Jan 16, 2006 2:02 am 

Hibernate Team
Hibernate Team



Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)

so you have mapped the id to a column which dont have data…?

(p.s. loadrunner is not a hibernatetool, I think it is some stresstesting tool they are using)


_________________
Max

Don’t forget to rate

Top

Profile  

thozhan_munus

Post subject:

PostPosted: Mon Jan 16, 2006 8:03 am 



Joined: Sun Jan 15, 2006 8:26 pm
Posts: 9

The id’s are created automatically by the oracle sequences.

This error happens when there are lot of concurrent users

are put into work through load runner.Otherwise it works fine.

Top

Profile  

max

Post subject:

PostPosted: Mon Jan 16, 2006 12:37 pm 

Hibernate Team
Hibernate Team



Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)

so you are most likely using the session unsafely — they are not threadsafe, so only use them in one thread at one time.


_________________
Max

Don’t forget to rate

Top

Profile  

thozhan_munus

Post subject:

PostPosted: Mon Jan 16, 2006 12:44 pm 



Joined: Sun Jan 15, 2006 8:26 pm
Posts: 9

How do i do that?..

Any settigs to be done in hibernat.cfg.xml?.

Top

Profile  

max

Post subject:

PostPosted: Mon Jan 16, 2006 12:50 pm 

Hibernate Team
Hibernate Team



Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)

huh ? no settings needed/possible.

just ensure that your software is written so you don’t use the same session in multiple threads.


_________________
Max

Don’t forget to rate

Top

Profile  

thozhan_munus

Post subject:

PostPosted: Mon Jan 16, 2006 1:04 pm 



Joined: Sun Jan 15, 2006 8:26 pm
Posts: 9

I guess we are already doing that.

Any other ideas?..

Is the following property is of any useful?.

<property name=»current_session_context_class»>thread</property>

Top

Profile  

zzyborg

Post subject:

PostPosted: Tue Jan 17, 2006 4:29 am 

Regular
Regular



Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india

Quote:

just ensure that your software is written so you don’t use the same session in multiple threads.

you may try to use a «ThreadLocal» sessions .


_________________
sHeRiN

thanks for your ratings …… :)

Top

Profile  

thozhan_munus

Post subject:

PostPosted: Tue Jan 17, 2006 9:51 am 



Joined: Sun Jan 15, 2006 8:26 pm
Posts: 9

We are already doing that…


_________________
Ramesh

Top

Profile  

tenwit

Post subject:

PostPosted: Tue Jan 17, 2006 4:58 pm 

Expert
Expert



Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008

You probably don’t want to use ThreadLocal sessions, as that implies long-lived sessions, which have separate issues that you’ll need to carefully manage. Use ThreadLocal SessionFactories, and get/release sessions as needed.

That won’t solve your null id problem though. You’ll have to debug that one yourself.

Top

Profile  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Как только программа заходит в метод loginClient выкидывает IllegalArgumentException: id to load is required for loading. Cуть метода получить ввод юзера из html формы, найти юзера по юзернайм в базе и сверить введенные и данные в базе.

@PostMapping("/login")
    public String loginClient(@ModelAttribute("input") Input input) throws Exception {
        String page = "";
        userInput = input.getPostUsername();
        Client existingClient = service.getClient(userInput);
        if((input.getPostUsername().equals(existingClient.getUsername())&
                (input.getPostPassword().equals(existingClient.getPassword())))){
            page = "Auth";
            SpotifyAPI newApi = new SpotifyAPI();
            newApi.startServer(8081);
        }
        else{
            page = "index";
        }
        return page;

 <form method="post" th:action="@{/login}" th:object="${input}" class="login">
    <p>
        <label th:for="postUsername">Username: </label>
        <input type="text" th:name="postUsername" id="postUsername"/>
    </p>

    <p>
        <label th:for="postPassword">Password: </label>
        <input type="text" th:name="postPassword" id="postPassword"/>
    </p>
java.lang.IllegalArgumentException: id to load is required for loading
    org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:93)
    org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:63)
    org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2920)
    org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1(SessionImpl.java:2904)
    org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2860)
    org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2904)
    org.hibernate.internal.SessionImpl.get(SessionImpl.java:1097)
    spotify.repository.ClientDAOImpl.getCustomer(ClientDAOImpl.java:58)
    spotify.service.ClientServiceImpl.getClient(ClientServiceImpl.java:41)
    java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.base/java.lang.reflect.Method.invoke(Method.java:567)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    com.sun.proxy.$Proxy46.getClient(Unknown Source)
    spotify.controller.AppControl.loginClient(AppControl.java:31)

ClientServiceImpl class:

@Override
    @Transactional
    public Client getClient(String username) {

        return clientDAO.getCustomer(username);
    }

DAOimpl

@Override
    public Client getCustomer(String username) {

        // get the current hibernate session
        Session currentSession = sessionFactory.getCurrentSession();

        // now retrieve/read from database using the primary key

        return currentSession.get(Client.class, username);
    }

Понравилась статья? Поделить с друзьями:
  • Нет доступа к папке как исправить виндовс 10
  • Непредвиденная сетевая ошибка торрент
  • Нет доступа к некоторым сайтам как исправить
  • Непредвиденная ошибка устройства при воспроизведении на тв
  • Нет доступа к интернету ростелеком как исправить