异常原因:在使用hibernate的时候,你想通过id进行查询,但是id为null,所以出现这个异常!
解决办法:打断点调试,先看清楚id是否有值!如果没有,问题就找到了!没有值就要搞清楚值在哪个地方传不见了!所以,检查代码,想办法搞到id的值!
我的问题是:在提交表单的时候没有提交id的值。
异常描述:
严重: Exception occurred during processing request: id to load is required for loading
java.lang.IllegalArgumentException: id to load is required for loading
at org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:109)
at org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:79)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2548)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
在提交form表单的时候:
<tr>
<td><label class="mylabel">用户名:</td>
<td>
<input name="oeadmin.name" type="text" value="${currentUser.name}" readonly="readonly"/>
</td>
</tr>
我根本就没有提交id,
然后我:
<tr>
<td><label class="mylabel">用户名:</td>
<td>
<input type="hidden" value="${currentUser.id }" name="oeadmin.id" /> <!--在此处-->
<input name="oeadmin.name" type="text" value="${currentUser.name}" readonly="readonly"/>
</td>
</tr>
就解决了!