Reputation: 591
For instance, I've created table using next DDL-query:
CREATE TABLE IF NOT EXISTS Person
(id int PRIMARY KEY, city_id int, name varchar, company varchar, age int)
WITH "template=partitioned, value_type=MyPerson";
Now i'm going to have it read from cache as MyPerson object. How do I do that? Do I need also to define MyPerson class? What if it would contain some (or totally) other fields that than Person table has?
Upvotes: 1
Views: 115
Reputation: 1785
It's easy to do. Skim through this GitHub project that shows how to blend SQL and key-value APIs together. It covers your scenario: https://github.com/dmagda/ignite_world_demo
Upvotes: 2
Reputation: 8390
You can either create the MyPerson
class or use withKeepBinary
flag and BinaryObject
API. See here for more details: https://apacheignite.readme.io/docs/binary-marshaller#binaryobject-cache-api
If you use the latter, you will have all the fields available. If you deserialize into a class instance, you will of course only have fields that are available in the class. Anything else would be ignored. Fields that exist in class but not in cache will be initialized with default values (nulls and zeros).
Upvotes: 3