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 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 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 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 Posted: Sun Jan 15, 2006 10:11 pm |
|
Newbie |
Please help: Hibernate version:3.0 java.lang.IllegalArgumentException: id to load is required for loading |
Top |
|
tenwit |
Post subject: Posted: Sun Jan 15, 2006 10:20 pm |
||
|
You’re passing null to Session().get(). You can’t get null. |
||
Top |
|
||
thozhan_munus |
Post subject: Posted: Sun Jan 15, 2006 11:02 pm |
|
This error comes only when we use |
Top |
|
tenwit |
Post subject: Posted: Sun Jan 15, 2006 11:46 pm |
||
|
I presume that that’s an Hibernate tool. Perhaps you could ask your question over on the Tools forum. |
||
Top |
|
||
max |
Post subject: Posted: Mon Jan 16, 2006 2:02 am |
||
|
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) |
||
Top |
|
||
thozhan_munus |
Post subject: Posted: Mon Jan 16, 2006 8:03 am |
|
The id’s are created automatically by the oracle sequences.
This error happens when there are lot of concurrent users |
Top |
|
max |
Post subject: Posted: Mon Jan 16, 2006 12:37 pm |
||
|
so you are most likely using the session unsafely — they are not threadsafe, so only use them in one thread at one time. |
||
Top |
|
||
thozhan_munus |
Post subject: Posted: Mon Jan 16, 2006 12:44 pm |
|
How do i do that?.. |
Top |
|
max |
Post subject: Posted: Mon Jan 16, 2006 12:50 pm |
||
|
huh ? no settings needed/possible. just ensure that your software is written so you don’t use the same session in multiple threads. |
||
Top |
|
||
thozhan_munus |
Post subject: Posted: Mon Jan 16, 2006 1:04 pm |
|
I guess we are already doing that. Is the following property is of any useful?. <property name=»current_session_context_class»>thread</property> |
Top |
|
zzyborg |
Post subject: Posted: Tue Jan 17, 2006 4:29 am |
||
|
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 . |
||
Top |
|
||
thozhan_munus |
Post subject: Posted: Tue Jan 17, 2006 9:51 am |
|
We are already doing that… |
Top |
|
tenwit |
Post subject: Posted: Tue Jan 17, 2006 4:58 pm |
||
|
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 |
|
||
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);
}