1. 程式人生 > >【SSH進階】java.lang.IllegalArgumentException: id to load is required for loading

【SSH進階】java.lang.IllegalArgumentException: id to load is required for loading

最近在做辦公自動化的專案,遇到這樣的問題java.lang.IllegalArgumentException: id to load isrequired for loading

Struts Problem Report
Struts has detected an unhandled exception:
Messages:
• id to load is required for loading
File:
org/hibernate/event/LoadEvent.java
Line number:
89

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

    org.hibernate.event.LoadEvent.(LoadEvent.java:89)
    org.hibernate.event.LoadEvent.(LoadEvent.java:61)
    org.hibernate.impl.SessionImpl.get(SessionImpl.java:1002)
    org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
    cn.itcast.oa.base.BaseDaoImpl.getById(BaseDaoImpl.java:52)
    cn.itcast.oa.base.BaseDaoImpl.detele(BaseDaoImpl.java:38)
    cn.itcast.oa.service.impl.RoleServiceImpl.detele(RoleServiceImpl.java:23)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
這個問題很明顯是id沒有獲取到,但是小編在前臺的url連結中已經看到了id的值了,那就是在呼叫介面的時候沒有將id的值獲取到.小編就開始斷點除錯.


在這裡報空指標了,而這個是最底層的,那麼就是他的上一次沒有獲取到,層層推進,找到他的上一級,才發現之前寫的時候沒有實現ModelDriven,直接是例項化了一個新的Role,這樣的話,role.getId肯定是null值了.


總結:

其實問題不難,只要靜下心來,一步步的分析就能將他解決.