Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DMI DS using criteria with type integer converts to long causing cast exception

    Using SmartGWT 2.5 Pro

    I've setup a DMI DataSource

    Code:
    <DataSource ID="issueLog" tableName="issueLog" 
    schemaBean="model.IssueResultLog">
        <serverObject className="dmi.IssueLogDMI"/>
        <fields>
            <field name="resultId"  title="Results ID"  
                 type="sequence"    primaryKey="true" />
            <field name="testId"    title="Test ID"  type="integer" />
            ...snip....
        </fields>
    </DataSource>
    The "IssueResultLog" model has testId as type int.
    When performing a fetch, I'm setting the criteria for testId.

    Code:
    Integer testId = 1;
    Criteria criteria = new Criteria();
    criteria.addCriteria("testId", testId);
    listGrid.fetchData(criteria);
    Transaction ends up having a type of LONG, and then I get a cast exception.

    Code:
    <criteria xsi:type="xsd:Object">
        <testId xsi:type="xsd:long">1</testId>
    </criteria>
    Code:
    00:28:35.727 [ERROR] 15:55:14.473:XRP0:WARN:RPCManager:java.lang.Long cannot be cast to java.lang.Integer, response: 
        {operationId: "issueLog_fetch", clientContext: Obj, context: Obj, transactionNum: 5, httpResponseCode: 200, httpResponseText: 
        "//isc_RPCResponseStart-->[{isDSResponse:..."[156], xmlHttpRequest: [object XMLHttpRequest], transport: "xmlHttpRequest", 
        status: -1, clientOnly: undef, httpHeaders: Obj, isStructured: true, callbackArgs: null, results: Obj, isDSResponse: true, 
        invalidateCache: false, data: "java.lang.Long cannot be cast to java.la..."[50], startRow: 0, endRow: 0, totalRows: 0}
    com.smartgwt.client.core.JsObject$SGWT_WARN: 15:55:14.473:XRP0:WARN:RPCManager:
        java.lang.Long cannot be cast to java.lang.Integer, response: {operationId: "issueLog_fetch",
    clientContext: Obj,
    context: Obj,
    transactionNum: 5,
    httpResponseCode: 200,
    httpResponseText: "//isc_RPCResponseStart-->[{isDSResponse:..."[156],
    xmlHttpRequest: [object XMLHttpRequest],
    transport: "xmlHttpRequest",
    status: -1,
    clientOnly: undef,
    httpHeaders: Obj,
    isStructured: true,
    callbackArgs: null,
    results: Obj,
    isDSResponse: true,
    invalidateCache: false,
    data: "java.lang.Long cannot be cast to java.la..."[50],
    startRow: 0,
    endRow: 0,
    totalRows: 0}
    	at sun.reflect.GeneratedConstructorAccessor104.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
    	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    	at java.lang.Thread.run(Thread.java:662)
    How so I avoid this, what do I need to do differently. Changing POJO's to have types of long is not an option.

    #2
    Conversion between these types is normally automatic. Please show the complete server log for the request (always do this - never snip).

    Comment


      #3
      DS Schema

      Code:
      <DataSource ID="issueLog" tableName="issueLog" schemaBean="com...model.IssueResultLog">
      
          <serverObject className="com...server.dmi.IssueLogDMI"/>
              
          <fields>
              <field name="resultId"  title="Results ID"  type="integer"    primaryKey="true" />
              <field name="testId"    title="Test ID"  type="integer" />
              <field name="timeStamp" title="Time Stamp"    type="datetime" />
              <field name="level"     title="Level"    type="text" />
              <field name="message"   title="Message"    type="text" />
              <field name="screenCapture"  title="Screen Capture"    type="text" />
              <field name="type"      title="Type"    type="text" />
              <field name="stackTrace" title="Stack Trace"    type="text" />
          </fields>
          
      </DataSource>

      Here is the model

      Code:
      public class IssueResultLog implements Serializable {
      
          private static final long serialVersionUID = 201107291500L;
      
          public static enum Type {
              TEST,
              CONFIG_BEFORE,
              CONFIG_AFTER,
              STACK_TRACE,
          }
          
          public static enum Level {
              INFO,
              WARN,
              ERROR,
              PASS,
              FAIL
          }
          
          private int resultId;
          private int testId;
          private Date timeStamp;
          private Level level;
          private String message;
          private String screenCapture;
          private IssueResultLog.Type type;
          private String stackTrace;
      
          ...snipped getters and setters...
      Post data being sent to the server.
      Why is this of type long??? <testId xsi:type="xsd:long">7839</testId>

      Code:
      <transaction xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:type="xsd:Object">
      <transactionNum xsi:type="xsd:long">6</transactionNum>
      <operations xsi:type="xsd:List">
          <elem xsi:type="xsd:Object">
              <criteria xsi:type="xsd:Object">
                  <testId xsi:type="xsd:long">7839</testId>
              </criteria>
              <operationConfig xsi:type="xsd:Object">
                  <dataSource>issueLog</dataSource>
                  <operationType>fetch</operationType>
                  <textMatchStyle>exact</textMatchStyle>
              </operationConfig>
              <startRow xsi:type="xsd:long">0</startRow>
              <endRow xsi:type="xsd:long">75</endRow>
              <sortBy xsi:type="xsd:List">
                  <elem>resultId</elem>
              </sortBy>
              <componentId>isc_ResultLogCanvas_5_2</componentId>
              <appID>builtinApplication</appID>
              <operation>issueLog_fetch</operation>
              <oldValues xsi:type="xsd:Object">
                  <testId xsi:type="xsd:long">7839</testId>
              </oldValues>
          </elem>
      </operations>
      </transaction>
      Server side log with exception: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer

      Code:
      === 2011-09-02 10:16:26,375 [l0-7] INFO  RequestContext - URL: '/testcaseapp/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0': Moz (Gecko) with Accept-Encoding header
      === 2011-09-02 10:16:26,383 [l0-7] DEBUG XML - Parsed XML from (in memory stream): 1ms
      === 2011-09-02 10:16:26,387 [l0-7] DEBUG XML - Parsed XML from ...\war\testcaseapp\sc\system\schema\List.ds.xml: 1ms
      === 2011-09-02 10:16:26,394 [l0-7] DEBUG RPCManager - Processing 1 requests.
      === 2011-09-02 10:16:26,404 [l0-7] DEBUG RPCManager - Request #1 (DSRequest) payload: {
          criteria:{
              testId:7839
          },
          operationConfig:{
              dataSource:"issueLog",
              operationType:"fetch",
              textMatchStyle:"exact"
          },
          startRow:0,
          endRow:75,
          sortBy:[
              "resultId"
          ],
          componentId:"isc_ResultLogCanvas_5_2",
          appID:"builtinApplication",
          operation:"issueLog_fetch",
          oldValues:{
              testId:7839
          }
      }
      === 2011-09-02 10:16:26,405 [l0-7] INFO  IDACall - Performing 1 operation(s)
      === 2011-09-02 10:16:26,412 [l0-7] DEBUG DataSourceDMI - Invocation threw exception
      java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
      	at com...dmi.IssueLogDMI.fetch(IssueLogDMI.java:24)
      	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 com.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:949)
      	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:610)
      	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64)
      	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1711)
      	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:199)
      	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:156)
      	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:121)
      	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:73)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
      	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at com...access.CustomConcurrentSessionFilter.doFilter(CustomConcurrentSessionFilter.java:56)
      	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
      	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
      	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
      	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.Server.handle(Server.java:324)
      	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

      Comment


        #4
        Look at the stack trace - that's you're own method crashing.

        Comment


          #5
          Thanks for pointing that out (I did in fact miss that). I can fix my code but it seems more like a workaround as I do expect value to be an Integer when in SmartClient converted it to a Long.

          Is this by design where all Integer criteria sent as Long's?
          If not, how can I get criteria values to be sent as Integers?

          Comment


            #6
            Methods such as DataSource.setProperties() will automatically adapt to a target bean's setters. Otherwise, it's a Long because that can fully represent the available precision client-side, whereas Integer cannot.

            Also, the system is doing what it advertises. "integer" is an abstract type that has different representation on the server, in the browser, in SQL etc. "Long" is an integer value, just a particular representation.

            Comment

            Working...
            X