1

I am working on a table which has about 15K rows and about 200 columns. I am trying to retrieve the data as JSON format and then I will use those JSON data to display into a JSP page.

To do this, I use Hibernate query like:

String s = "select h.bookID, h.bookTitle, h.entryDate from BookHistory h";      
Query q = s.createQuery(qs);        
List list = q.setMaxResults(309).list();

The JSON data is OK upto the 1st 309 rows. But if I choose more than 309 rows then there is no JSON data output.

BookHistory.java

public class BookHistory implements Serializable{       
    @Id
    @GeneratedValue(...)
    @SequenceGenerator(...)
    @Column(name = "ID")
    String bookID;
    String bookTitle;
    Date entryDate;
    ........            
}

Action Class for JSON result:

public class JSONBookHistory extends ActionSupport {

    private static final long serialVersionUID = 1L;

    List<BookHistory> gridModel;

    //getter & setter

    public String execute(){
        ...
        gridModel = dao....;

        return SUCCESS;
    }

    public String getJSON(){
        return execute();
    }
}

JSP page:

    <s:url var="remoteurl" action="bookHistoryAction" />
    <sj:head jqueryui="true" jquerytheme="redmond" />
    <sjg:grid id="gridtable1" dataType="json" href="%{#remoteurl}" gridModel="gridModel">
        <sjg:gridColumn name="bookID" index="bookID" title="bookID" sortable="true" width="80" />
        .....
    </sjg:grid>

Exception

org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException
    org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:230)
    org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160)
    org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126)
    org.apache.struts2.json.JSONWriter.write(JSONWriter.java:94)
    org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:115)
    org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:200)
    org.apache.struts2.json.JSONResult.execute(JSONResult.java:172)
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:366)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

Any suggestion to retrieve all the data?

user3150012
  • 109
  • 9
  • You want to show all 15k rows in JSP at once? What do you mean it is ok up to 309 rows, then what happens? – Aleksandr M Jan 23 '14 at 20:46
  • I want to show only the first 500 rows with only 3 columns data. If i tried to fetch 309 rows then the data is being displayed into the jsp page. But rows more than 309 like 310 or more, the values are not coming and I am getting the blank page – user3150012 Jan 23 '14 at 20:48
  • So post exception and code where you doing something with json. – Aleksandr M Jan 23 '14 at 20:49
  • And if you need only 3 columns then select just this 3 columns. – Aleksandr M Jan 23 '14 at 20:50
  • I did that and still getting the same problem. Exception is like: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.reflect.InvocationTargetException org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:230) org.apache.struts2.json.JSONWriter.process(JSONWriter.java:160) org.apache.struts2.json.JSONWriter.value(JSONWriter.java:126) org.apache.struts2.json.JSONWriter.write(JSONWriter.java:94) org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:115) org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:200) – user3150012 Jan 23 '14 at 20:55
  • Have you considered that row 310 might hold some unparseable data? – Aleksandr M Jan 23 '14 at 21:15
  • i also checked that using the where clause with the condition (id between 305 to 315) and the data is coming – user3150012 Jan 23 '14 at 21:19
  • Row count != element id. Check your data. Debug you code to see what exactly is failing. – Aleksandr M Jan 23 '14 at 21:43
  • `java.lang.reflect.InvocationTargetException` is caused if underlying method throws an exception. May be you can refer This [InvocationTargetException][http://stackoverflow.com/questions/6020719/what-could-cause-java-lang-reflect-invocationtargetexception] – Rookie007 Jan 24 '14 at 00:29
  • @user3150012 Can you post your jsp and Action class code? – Uchenna Nwanyanwu Jan 24 '14 at 04:52
  • What is the cause of `InvocationTargetException` could it be NPE or something else? – Roman C Jan 24 '14 at 14:10
  • @Uchenna Nwanyanwu: I have added those code. – user3150012 Jan 24 '14 at 20:27
  • @ Roman C : still I could not solved the problem. I am still debugging this. I tried after deleting some rows and still the program stuck after 309 rows of data. – user3150012 Jan 24 '14 at 20:29

1 Answers1

0

The InvocationTargetException is a wrapper for some other exception being thrown by the method invoked via reflection API. You should catch it and 'unwrap' by calling getCause().

The bean() method of JSONWriter invokes getter methods for all properties of an object being rendered: http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts/struts2-json-plugin/2.3.15.2/org/apache/struts2/json/JSONWriter.java#JSONWriter.bean%28java.lang.Object%29

So, you see an exception throwed while calling some getXXX() method for 310th object in list() result. It should be some Hibernate's proxy method, you'll find detailed information in cause's description.

rglv
  • 16
  • 1