You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by zaid <za...@gmail.com> on 2017/02/16 10:48:18 UTC

@SqlQueryField on composite primary key

Hi,

My POJO has composite primary key.

e.g.

public class Person {

PersonPK id;

String name;

}

public class PersonPK {
Long id1;
String personType;
}

These classes are just for example purpose. My question is - can I apply
@SqlQueryField directly on id field in Person class which is of type
PersonPK. How this will be used while creating table in H2?





--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/SqlQueryField-on-composite-primary-key-tp10666.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: @SqlQueryField on composite primary key

Posted by Vladimir Ozerov <vo...@gridgain.com>.
Hi Zaid,

No. You should put @QuerySqlField annotation on these fields in this case.

On Thu, Feb 16, 2017 at 3:39 PM, zaid <za...@gmail.com> wrote:

> Hi Vladimir,
> Will I be able to query on field of PersonPK? e.g.
>
> select Person.name from Person where *id.personType* = 'soft';
>
> Regards
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/QuerySqlField-on-composite-
> primary-key-tp10666p10671.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: @SqlQueryField on composite primary key

Posted by zaid <za...@gmail.com>.
Hi Vladimir,
Will I be able to query on field of PersonPK? e.g.

select Person.name from Person where *id.personType* = 'soft';

Regards



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/QuerySqlField-on-composite-primary-key-tp10666p10671.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: @SqlQueryField on composite primary key

Posted by Vladimir Ozerov <vo...@gridgain.com>.
zaid,
In this case "id" column will be created. If you query this attribute,
PersonPK will be returned.

Sergi,
This is in fact widely-used pattern which I saw many times in production
systems. It allows user to have self-contained object. Otherwise one will
have to introduce third value object which will hold both key and val parts.

On Thu, Feb 16, 2017 at 2:15 PM, Sergi Vladykin <se...@gmail.com>
wrote:

> If you are going to store this stuff in cache like
>
> cache.put(myPersonPK, myPerson)
>
> then storing PersonPK inside of Person is bad idea, because PK will be
> stored twice in cache.
>
> I'm not sure I understand your question, but it seems to me that you don't
> need to do anything here because cache key is always accessible from SQL as
> _KEY field.
>
> Sergi
>
> 2017-02-16 13:48 GMT+03:00 zaid <za...@gmail.com>:
>
>> Hi,
>>
>> My POJO has composite primary key.
>>
>> e.g.
>>
>> public class Person {
>>
>> PersonPK id;
>>
>> String name;
>>
>> }
>>
>> public class PersonPK {
>> Long id1;
>> String personType;
>> }
>>
>> These classes are just for example purpose. My question is - can I apply
>> @SqlQueryField directly on id field in Person class which is of type
>> PersonPK. How this will be used while creating table in H2?
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://apache-ignite-users.705
>> 18.x6.nabble.com/SqlQueryField-on-composite-primary-key-tp10666.html
>> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>>
>
>

Re: @SqlQueryField on composite primary key

Posted by Sergi Vladykin <se...@gmail.com>.
If you are going to store this stuff in cache like

cache.put(myPersonPK, myPerson)

then storing PersonPK inside of Person is bad idea, because PK will be
stored twice in cache.

I'm not sure I understand your question, but it seems to me that you don't
need to do anything here because cache key is always accessible from SQL as
_KEY field.

Sergi

2017-02-16 13:48 GMT+03:00 zaid <za...@gmail.com>:

> Hi,
>
> My POJO has composite primary key.
>
> e.g.
>
> public class Person {
>
> PersonPK id;
>
> String name;
>
> }
>
> public class PersonPK {
> Long id1;
> String personType;
> }
>
> These classes are just for example purpose. My question is - can I apply
> @SqlQueryField directly on id field in Person class which is of type
> PersonPK. How this will be used while creating table in H2?
>
>
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/SqlQueryField-on-composite-primary-key-tp10666.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>