Announcement

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

    Foreign keys on Datasources with same primary key ID?

    Hi,

    I'm trying to integrate SGWT EE with our application and I seem to have hit a little snag. Turns out all our DB tables have a primary key named "id". The name remains the same throughout the 300+ tables.

    Now I'm trying to fire a fetch query with a criteria like so

    Code:
    						DataSource leadSubDs = DataSource.get("LeadSubscribedUsers");
    						Criteria cr = new Criteria();
    						cr.addCriteria("leads.id", Long.valueOf(id));
    						cr.addCriteria("users", userId);
    						leadSubDs.fetchData(cr, new DSCallback() {
    							public void execute(DSResponse response, Object rawData, DSRequest request) {
    								Record[] responseData = response.getData();
    for(Record record: responseData){
    									String eventTypeCode = "";
    									String actionTypeCode = "";
    									Object obj = JSOHelper.convertToJava(record.getJsObj());
    ....
    My criteria here however seems to get ignored:

    Code:
        criteria:{
            "leads.id":10,
            users:1
        },
        operationConfig:{
            dataSource:"LeadSubscribedUsers",
            operationType:"fetch",
            textMatchStyle:"exact"
        },
        appID:"builtinApplication",
        operation:"LeadSubscribedUsers_fetch",
        oldValues:{
            "leads.id":10,
            users:1
        }
    }
    === 2014-09-03 13:04:32,925 [ec-7] INFO  IDACall - Performing 1 operation(s)
    === 2014-09-03 13:04:32,926 [ec-7] DEBUG ISCKeyedObjectPool - Borrowing object for 'leads'
    === 2014-09-03 13:04:32,926 [ec-7] WARN  DSRequest - In criteria, definition 'leads.id' refers to a field name ('id') that is already declared on this dataSource ('LeadSubscribedUsers').  Ignoring this criteria entry.
    I've also tried to write my code like so:

    Code:
    						Criteria cr = new Criteria();
    						cr.addCriteria("leads", Long.valueOf(id));
    but that throws another exception:

    Code:
    === 2014-09-03 14:13:13,207 [ec-2] DEBUG ISCKeyedObjectPool - Borrowing object for 'LeadSubscribedUsers'
    === 2014-09-03 14:13:13,208 [ec-2] DEBUG RPCManager - Request #1 (DSRequest) payload: {
        criteria:{
            leads:10,
            users:1
        },
        operationConfig:{
            dataSource:"LeadSubscribedUsers",
            operationType:"fetch",
            textMatchStyle:"exact"
        },
        appID:"builtinApplication",
        operation:"LeadSubscribedUsers_fetch",
        oldValues:{
            leads:10,
            users:1
        }
    }
    === 2014-09-03 14:13:13,208 [ec-2] INFO  IDACall - Performing 1 operation(s)
    === 2014-09-03 14:13:13,208 [ec-2] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
    === 2014-09-03 14:13:13,208 [ec-2] DEBUG DeclarativeSecurity - DataSource LeadSubscribedUsers is not in the pre-checked list, processing...
    === 2014-09-03 14:13:13,208 [ec-2] DEBUG AppBase - [builtinApplication.LeadSubscribedUsers_fetch] No userTypes defined, allowing anyone access to all operations for this application
    === 2014-09-03 14:13:13,209 [ec-2] DEBUG AppBase - [builtinApplication.LeadSubscribedUsers_fetch] No public zero-argument method named '_LeadSubscribedUsers_fetch' found, performing generic datasource operation
    === 2014-09-03 14:13:13,209 [ec-2] DEBUG JPADataSource - [builtinApplication.LeadSubscribedUsers_fetch] Creating EntityManager and starting transaction.
    === 2014-09-03 14:13:13,217 [ec-2] DEBUG DSRequest - [builtinApplication.LeadSubscribedUsers_fetch] Clobbering existing FreeResourcesHandler of type 'com.isomorphic.jpa.JPA2DataSource' with a 'com.isomorphic.jpa.JPA2DataSource'
    === 2014-09-03 14:13:13,217 [ec-2] DEBUG JPADataSource - [builtinApplication.LeadSubscribedUsers_fetch] Executing fetch.
    === 2014-09-03 14:13:13,218 [ec-2] DEBUG ISCKeyedObjectPool - [builtinApplication.LeadSubscribedUsers_fetch] Borrowing object for 'Leads'
    === 2014-09-03 14:13:13,218 [ec-2] DEBUG JPADataSource - [builtinApplication.LeadSubscribedUsers_fetch] Marking transaction for roll back.
    === 2014-09-03 14:13:13,218 [ec-2] DEBUG JPADataSource - [builtinApplication.LeadSubscribedUsers_fetch] Got exception while executing. Transaction will be rolled back.
    java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map
    	at com.isomorphic.jpa.JPADataSource.createQuery(JPADataSource.java:1910)
    	at com.isomorphic.jpa.JPADataSource.executeFetch(JPADataSource.java:691)
    	at com.isomorphic.datasource.DataSource.execute(DataSource.java:1517)
    	at com.isomorphic.jpa.JPADataSource.execute(JPADataSource.java:651)
    	at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:723)
    	at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
    	at com.isomorphic.application.AppBase.execute(AppBase.java:491)
    	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2534)
    	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:215)
    	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:172)
    	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:137)
    	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:73)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:62)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:260)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    	at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    	at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    	at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at com.bmf.servlet.filters.ReferralFilter.doFilter(ReferralFilter.java:59)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at com.bmf.servlet.filters.LoggerFilter.doFilter(LoggerFilter.java:50)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    	at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:123)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:171)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	at java.lang.Thread.run(Thread.java:722)

    Here are my .ds.xml files:

    Code:
    <DataSource  
        ID="LeadSubscribedUsers"  
        serverType="jpa"    
        serverConstructor="com.isomorphic.jpa.JPA2DataSource"
        dropExtraFields="true"
        beanClassName="com.bmf.domain.LeadSubscribedUsers" 
        schemaBean="com.bmf.domain.LeadSubscribedUsers">
        
        <fields>  
            <field name="id"/>
            <field name="eventTypes" type="EventTypes" foreignKey="EventTypes.id"/>
            <field name="actionTypes" type="ActionTypes" foreignKey="ActionTypes.id"/> 
            <field name="leads" type="Leads" foreignKey="Leads.id"/>
            <field name="users" type="Users" foreignKey="Users.id"/>  
        </fields>
          
    </DataSource>
    Code:
    <DataSource 
    	allowAdvancedCriteria="true"
    	dropExtraFields="true"
    	beanClassName="com.bmf.domain.Leads"
    	ID="Leads"
    	entityName="com.bmf.domain.Leads"
    	serverType="jpa"
    >
    	<fields>
    		<field hidden="true" primaryKey="true" name="id" length="255" canEdit="false" required="false" type="sequence"></field>
    		<field name="lastCommentAt" length="19" canEdit="true" required="true" type="datetime"></field>
    		<field name="priorityPoints" length="255" canEdit="true" required="true" type="integer"></field>
    		<field name="receivedAt" length="19" canEdit="true" required="true" type="datetime"></field>
    		<field name="updatedAt" length="19" canEdit="true" required="true" type="datetime"></field>
    	</fields>
    </DataSource>
    Is there a way I can get around this without having to rename every primary key column in my DB and associated JPA entities?

    #2
    Just to add a bit more to my initial post. I know that if for instance I remove the type="Leads" part from the fields in my .ds.xml, I would be able to fire my query fine.

    Code:
    <!-- Auto-generated from Hibernate mapping com.bmf.domain.LeadSubscribedUsers -->
    
    <DataSource 
    	allowAdvancedCriteria="true"
    	dropExtraFields="true"
    	beanClassName="com.bmf.domain.LeadSubscribedUsers"
    	ID="LeadSubscribedUsers"
    	generatedBy="v9.1p_2014-08-20/EVAL Deployment 2014-08-20"
    	entityName="com.bmf.domain.LeadSubscribedUsers"
    	serverType="jpa"
    >
    	<fields>
    		<field hidden="true" primaryKey="true" name="id" length="255" canEdit="false" required="false" type="sequence"></field>
            <field name="eventTypes" type="EventTypes" foreignKey="EventTypes.id"/>
            <field name="actionTypes" type="ActionTypes" foreignKey="ActionTypes.id"/> 
            <field name="leads" foreignKey="Leads.id"/>
            <field name="users" foreignKey="Users.id"/>  
    	</fields>
    </DataSource>
    but I can't do this since I need to parse the JSObj from the response to Java object later to perform some business logic.

    So please do keep that consideration in mind when suggesting a solution.

    Thanks very much

    Comment


      #3
      Hi nitrojin,

      you are querying LeadSubscribedUsers for a specific leads.id (btw not a correct field name, if used as field).
      Your actual field is named leads in LeadSubscribedUsers.ds.xml.
      So your criteria should be for "leads" as well.

      You need you fk-relation only if you want to ask for other fields of Leads in DataSource LeadSubscribedUsers, e.g. priorityPoints='A'.

      Therefore include a field definition in LeadSubscribedUsers:
      <field includeFrom="Leads.priorityPoints" /> and create a Criteria for this. See client/docs/DataSourceRelations.

      Best regards,
      Blama

      Comment


        #4
        Thanks for the quick reply Blama. I was able to get this figured out. includeFrom seems to work great and I can avoid the less than ideal JS to Java object conversion step

        Comment

        Working...
        X