You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Prasad Bhalerao <pr...@gmail.com> on 2018/02/19 14:25:31 UTC

QueryEntities in Ingnite

Hi,

As per this link (
https://stackoverflow.com/questions/36773011/what-is-the-difference-between-a-primary-key-and-a-surrogate-key),
I have created the QueryEntities as follows. I have not set the fields and
indexes explicitly as it is already define in my value Pojo class.

private static QueryEntity createIPV4RangeDataEntity() {
    QueryEntity ipV4RangeDataEntity = new QueryEntity();
    ipV4RangeDataEntity.setValueType(IPV4RangeData.class.getName());
    ipV4RangeDataEntity.setKeyType(IPRangeDataKey.class.getName());
    return ipV4RangeDataEntity;
}

I am using following code to get the number of records for a given groupId.

try (QueryCursor<List<?>> cursor = ipV4RangeDataCache.query(new
SqlFieldsQuery("select count(1) from IPV4RANGEDATA where assetGroupId
= 10")) )  {
    for (List<?> row : cursor)
        System.out.println("count=" + row.get(0));
}

But when execute above code, I get following exception. Do I have to
redefine all the fields,qury fields and indexes in QueryEntity for each
cache? Can some one please advise?

 Caused by: org.h2.jdbc.JdbcSQLException: Column "GROUPID" not found; SQL
statement:
select count(1) from IPV4RANGEDATA where groupId = 10 [42122-196]


Pojo:

public class IPV4RangeData implements Serializable {

    private long id;

    @QuerySqlField(orderedGroups = {@QuerySqlField.Group(name =
"ipv4_range_idx", order = 0)})
    private long groupId;

    private int assetType;

    @QuerySqlField(orderedGroups = {@QuerySqlField.Group(name =
"ipv4_range_idx", order = 1)})
    private long startIp;

    @QuerySqlField(orderedGroups = {@QuerySqlField.Group(name =
"ipv4_range_idx", order = 1)})
    private long endIp;






Thanks,
Prasad

Re: QueryEntities in Ingnite

Posted by Mikhail <mi...@gmail.com>.
>Does setting index of cache configuration solves the column Groupid not
found problem.

yes, it does.

>Cause I am not setting fields explicitly in QueryEntity. Is it required to
set fields in QueryEntity when annotations are used in Pojo?

you must choose only one approach to describe an object for indexing: 1.
Annotations 2. QueryEntity

if you choose QueryEntity, you will need to describe object fields according
to documentation I provided above.

Thanks,
Mike.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntities in Ingnite

Posted by Prasad Bhalerao <pr...@gmail.com>.
Does setting index of cache configuration solve the coumn Groupid not found
problem.
Cause I am not setting fields explicitly in QueryEntity. Is it required to
set fields in QueryEntity when annotations are used in Pojo?

On Feb 19, 2018 8:45 PM, "Mikhail" <mi...@gmail.com> wrote:

Hi,

there's two way to index objects in cache:
1. by annotations:
https://apacheignite.readme.io/docs/cache-queries#section-qu
ery-configuration-by-annotations
2. by QueryEntity:
https://apacheignite.readme.io/docs/cache-queries#section-qu
ery-configuration-using-queryentity

But you can't mix both, please define fields in QueryEntity or set indexed
objects by: CacheConfiguration.setIndexedTypes(MyKey.class, MyValue.class)

Thanks,
Mike.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntities in Ingnite

Posted by Mikhail <mi...@gmail.com>.
Hi,

there's two way to index objects in cache:
1. by annotations:
https://apacheignite.readme.io/docs/cache-queries#section-query-configuration-by-annotations
2. by QueryEntity:
https://apacheignite.readme.io/docs/cache-queries#section-query-configuration-using-queryentity

But you can't mix both, please define fields in QueryEntity or set indexed
objects by: CacheConfiguration.setIndexedTypes(MyKey.class, MyValue.class) 

Thanks,
Mike.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/