@QuerySqlField on composite primary key

classic Classic list List threaded Threaded
5 messages Options
zaid zaid
Reply | Threaded
Open this post in threaded view
|

@QuerySqlField on composite primary key

This post was updated on .
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 @QuerySqlField directly on id field in Person class which is of type PersonPK. How this will be used while creating table in H2?

Sergi Vladykin Sergi Vladykin
Reply | Threaded
Open this post in threaded view
|

Re: @SqlQueryField on composite primary key

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 <[hidden email]>:
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.

Vladimir Ozerov Vladimir Ozerov
Reply | Threaded
Open this post in threaded view
|

Re: @SqlQueryField on composite primary key

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 <[hidden email]> 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 <[hidden email]>:
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.


zaid zaid
Reply | Threaded
Open this post in threaded view
|

Re: @SqlQueryField on composite primary key

Hi Vladimir,
Will I be able to query on field of PersonPK? e.g.

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

Regards
Vladimir Ozerov Vladimir Ozerov
Reply | Threaded
Open this post in threaded view
|

Re: @SqlQueryField on composite primary key

Hi Zaid,

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

On Thu, Feb 16, 2017 at 3:39 PM, zaid <[hidden email]> 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.