JSON java.sql.SQLException:不支持定位更新

时间:2013-04-10 04:24:01

标签: ajax json hibernate spring-mvc java-web-start

我正在尝试在Java Web中使用JSON。通过调用JSONArray.fromObject()将List转换为JSONArray,但抛出异常如下:

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方法。但它仍然无法正常工作。我在这里寻求帮助。提前致谢

1 个答案:

答案 0 :(得分:0)

这似乎是 Hibernate延迟加载问题。

如果要格式化的对象是某种hibernate模型类,并将这些类配置为延迟加载,则会出现此问题。

原因是hibernate使用cglib动态生成这个模型类(使用子类方式生成类),这些子类包含新属性,如“hibernateLazyInitializer”。然后JSONObject也会尝试序列化这些新属性。然后发生异常。

您可以尝试添加以下代码来解决此问题:

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