2013-04-10 67 views
0

我想在Java Web中使用JSON。轉換列表以JSONArray通過調用JSONArray.fromObject(),但拋出的異常如下:JSON java.sql.SQLException:定位更新不支持

java.sql.SQLException: Positioned Update not supported. 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929) 
    at com.mysql.jdbc.ResultSetImpl.getCursorName(ResultSetImpl.java:2130) 
    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:597) 
    at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2170) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1332) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:770) 
    at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:846) 
    at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:918) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONObject._processValue(JSONObject.java:2808) 
    at net.sf.json.JSONObject.processValue(JSONObject.java:2874) 
    at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) 
    at net.sf.json.JSONObject.setValue(JSONObject.java:1577) 
    at net.sf.json.JSONObject._fromBean(JSONObject.java:934) 
    at net.sf.json.JSONObject.fromObject(JSONObject.java:168) 
    at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) 
    at net.sf.json.JSONArray._processValue(JSONArray.java:2514) 
    at net.sf.json.JSONArray.processValue(JSONArray.java:2539) 
    at net.sf.json.JSONArray.addValue(JSONArray.java:2526) 
    at net.sf.json.JSONArray._fromCollection(JSONArray.java:1057) 
    at net.sf.json.JSONArray.fromObject(JSONArray.java:123) 
    at org.vclub.model.json.Page2Json.getJsonFromList(Page2Json.java:11) 
    at org.vclub.controller.TopicController.loadMoreTopic(TopicController.java:91) 
    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:597) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:185) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:502) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:465) 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:863) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:851) 
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:767) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) 
    at org.apache 
.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    at java.lang.Thread.run(Thread.java:619) 

實際上,根據網上說,有兩種解決方案,修改struts.xml中或刪除DAO的getter方法領域。我沒有使用struts,所以我選擇刪除服務中的DAO字段的getter方法。但它仍然無法正常工作。我在這裏尋找幫助。在此先感謝

回答

0

看起來像一個休眠懶加載問題。

如果要格式化的對象是某種類型的hibernate模型類,並將這些類配置爲延遲加載,則會發生此問題。

原因是hibernate使用cglib來動態生成這個模型類(使用子類方法來生成類),那些子類包含像「hibernateLazyInitializer」這樣的新屬性。然後JSONObject也會嘗試序列化這些新的屬性。然後發生異常。

你可以嘗試添加以下代碼來解決這個問題:

JsonConfig cfg = new JsonConfig(); 
cfg.setExcludes(new String[]{"handler","hibernateLazyInitializer"}); 
JSONObject json = JSONObject.fromObject(obj,cfg);