Actually, this is what's happening:

This is the code:

package org.apache.ignite.organization;

import java.util.List;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.KeyStore.Entry;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.cache.Cache;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.transactions.Transaction;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;


public class Demo {
        

           static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
           static final String DB_URL = "jdbc:mysql://localhost/ORG";
           static final String USER = "root";
           static final String PASS = "mysql";
           
           private static class MySQLDemoStoreFactory<K, V> extends
CacheJdbcPojoStoreFactory<K, V> {
                 //{@inheritDoc} 
                 @Override public CacheJdbcPojoStore<K, V> create() {
                    
                    
                    MysqlDataSource dataSource = new MysqlDataSource(); 
                    dataSource.setURL("jdbc:mysql://localhost/ORG"); 
                    dataSource.setUser("root"); 
                    dataSource.setPassword("mysql"); 
                    setDataSource(dataSource);
                    return super.create();
                                
                }
                
            }

    /**
     * Executes demo.
     */
    public static void main(String[] args) throws IgniteException {
        System.out.println(">>> Start demo...");
    

        // Start Ignite node.
        try (Ignite ignite =
Ignition.start("examples/config/example-ignite.xml")) {
                
                CacheConfiguration<PersonKey, Person> cfg =
                    CacheConfig.cache("PCache", new
MySQLDemoStoreFactory<PersonKey, Person>());
            
            try (IgniteCache<PersonKey, Person> pCache =
ignite.getOrCreateCache(cfg)) {
                // Preload cache from database.
                preload1(pCache);
            }
                
                CacheConfiguration<OrganizationKey, Organization> cfg1 =
                    CacheConfig.cache("OrgCache", new
MySQLDemoStoreFactory<OrganizationKey, Organization>());
            
            try (IgniteCache<OrganizationKey, Organization> orgCache =
ignite.getOrCreateCache(cfg1)) {
                // Preload cache from database.
                preload(orgCache);
            }
            
            try (IgniteCache<PersonKey, Person> pCache =
ignite.cache("PCache")) {
                
                
                SqlFieldsQuery sql = new SqlFieldsQuery(
                            "select Person.first_name  "
                                + "from Person, \"OrgCache\".Organization where 
"
                                + "Person.orgId = Organization.orgId "
                                + "and Organization.orgname = ?");
                System.out.println(sql);

                        // Execute the query and obtain the query result cursor.
                        try (QueryCursor<List&lt;?>> cursor = 
pCache.query(sql.setArgs("Ignite"))) {
                            for (List<?> row : cursor)
                                System.out.println("Person name= " + row);
                        }
            }
        }
    }
    private static void preload(IgniteCache<OrganizationKey, Organization>
cache) {
        System.out.println();
        System.out.println(">>> Loading entries from Organization table.");

        // Preload all person keys that are less than or equal to 3.
        cache.loadCache(null, OrganizationKey.class.getName(), "select *
from organization");
        
        

        for (Cache.Entry<OrganizationKey, Organization> org : cache)
            System.out.println(">>> Loaded Organization: " + org);
    }
    
    private static void preload1(IgniteCache<PersonKey, Person> cache) {
        System.out.println();
        System.out.println(">>> Loading entries from Person table.");

        // Preload all person keys that are less than or equal to 3.
        cache.loadCache(null, PersonKey.class.getName(), "select * from
person");
        
        

        for (Cache.Entry<PersonKey, Person> person : cache)
            System.out.println(">>> Loaded Person: " + person);
    }

   
}

And this is the error I'm getting:

Exception in thread "main" javax.cache.CacheException: class
org.apache.ignite.IgniteException: Failed to parse query: select
Person.first_name  from Person, "OrgCache".Organization where Person.orgId =
Organization.orgId and Organization.orgname = ?
        at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:657)
        at org.apache.ignite.organization.Demo.main(Demo.java:91)
Caused by: class org.apache.ignite.IgniteException: Failed to parse query:
select Person.first_name  from Person, "OrgCache".Organization where
Person.orgId = Organization.orgId and Organization.orgname = ?
        at
org.apache.ignite.internal.processors.query.GridQueryProcessor.queryTwoStep(GridQueryProcessor.java:811)
        at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:648)
        ... 1 more
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to parse
query: select Person.first_name  from Person, "OrgCache".Organization where
Person.orgId = Organization.orgId and Organization.orgname = ?
        at
org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:1787)
        at
org.apache.ignite.internal.processors.query.GridQueryProcessor.queryTwoStep(GridQueryProcessor.java:804)
        ... 2 more
Caused by: javax.cache.CacheException: Failed to parse query: select
Person.first_name  from Person, "OrgCache".Organization where Person.orgId =
Organization.orgId and Organization.orgname = ?
        at
org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:1043)
        at
org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:806)
        at
org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:804)
        at
org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)
        at
org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:1769)
        ... 3 more
Caused by: org.h2.jdbc.JdbcSQLException: Column "PERSON.FIRST_NAME" not
found; SQL statement:
select Person.first_name  from Person, "OrgCache".Organization where
Person.orgId = Organization.orgId and Organization.orgname = ? [42122-175]



--
View this message in context: 
http://apache-ignite-users.70518.x6.nabble.com/How-to-load-2-tables-in-a-cache-tp4026p4082.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Reply via email to