[
https://issues.apache.org/jira/browse/IGNITE-13028?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17208460#comment-17208460
]
Ilya Kazakov commented on IGNITE-13028:
---------------------------------------
I.
There are several questions about semantics of your proposal.
In your example we using composite key, which consists of *ID* and
*COUNTRYCODE* (but actually we know the *ID* field is unique, so you write a
query like this *"select * where id = ?"*).
But in general, if we write *findById(<T> id)* method and have a composite key
in the repository, let's decide what semantic will be behind id. I see two
options:
# in the composite key look for all fields, which have the same type as an
argument in *findById(<Type> s)*, and generate the query using this fields.
# in the composite key look for an field with the name *ID*, and generate
query using this field.
Also, since we only use one field from the entire composite key, it would be
more correct to write that the *findById (<T> id)* method should return not one
value, but a collection, or the first one that comes across. Let's define the
semantics here too.
II.
About primitive types in keys. There is a method extended from CrudRepository.
For example in CountryRepository it is:
{code:java}
@Override public Optional<Country> findById(String s);{code}
Therefore we could not write:
{code:java}
public Cache.Entry<String, Country> findById(String s);{code}
> Spring Data integration doesn't introspect the fields of the key object
> -----------------------------------------------------------------------
>
> Key: IGNITE-13028
> URL: https://issues.apache.org/jira/browse/IGNITE-13028
> Project: Ignite
> Issue Type: Improvement
> Components: spring, springdata
> Affects Versions: 2.8
> Reporter: Denis A. Magda
> Assignee: Ilya Kazakov
> Priority: Major
> Labels: newbie
> Fix For: 2.10
>
>
> Suppose you have key and value POJOs associated with Ignite caches/tables:
> * Key:
> https://github.com/GridGain-Demos/ignite-spring-data-demo/blob/master/src/main/java/org/gridgain/demo/springdata/model/CityKey.java
> * Value:
> https://github.com/GridGain-Demos/ignite-spring-data-demo/blob/master/src/main/java/org/gridgain/demo/springdata/model/City.java
> The key object includes a couple of fields ({{id}} and {{countryCode}}) that
> are not visible to the Spring's query-autogeneration feature. For instance,
> you have to use direct queries if want to get [all the cities with a specific
> value of {{id}}
> field|https://github.com/GridGain-Demos/ignite-spring-data-demo/blob/master/src/main/java/org/gridgain/demo/springdata/dao/CityRepository.java#L42]:
> {code:java}
> @Query("SELECT * FROM City WHERE id = ?")
> public Cache.Entry<CityKey, City> findById(int id);
> {code}
> If the query-autogeneration feature could introspect the metadata of the key,
> then you would not need to fall back to the direct queries and would add the
> following query to the repository:
> {code:java}
> public Cache.Entry<CityKey, City> findById(int id);
> {code}
> The same issue exists if a key is of a primitive type (Integer, String, etc.)
> To reproduce you can use this project:
> https://github.com/GridGain-Demos/ignite-spring-data-demo
--
This message was sent by Atlassian Jira
(v8.3.4#803005)