[
https://issues.apache.org/jira/browse/IGNITE-23756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17901369#comment-17901369
]
Andrey Novikov commented on IGNITE-23756:
-----------------------------------------
[~myskov] Thank you for the contribution!
> Spring Data: Add support for type converters
> --------------------------------------------
>
> Key: IGNITE-23756
> URL: https://issues.apache.org/jira/browse/IGNITE-23756
> Project: Ignite
> Issue Type: Improvement
> Reporter: Maksim Myskov
> Assignee: Maksim Myskov
> Priority: Major
>
> The current spring data extension has issues with working with LocalDateTime
> type.
> LocalDateTime maps to Ignite's Timestamp, but it cannot be converted
> automatically.
>
> {code:java}
> java.lang.IllegalArgumentException: Can not set java.time.LocalDateTime field
> Person.createdAt to java.sql.Timestamp {code}
> We need to get support for spring data converters
> [https://docs.spring.io/spring-data/jpa/reference/data-commons/custom-conversions.html.]
>
> Reproduce scenario:
> {code:java}
> package util;
> import java.time.LocalDateTime;
> import java.util.List;
> import org.apache.ignite.Ignite;
> import org.apache.ignite.IgniteCache;
> import org.apache.ignite.Ignition;
> import org.apache.ignite.cache.query.SqlFieldsQuery;
> import org.apache.ignite.cache.query.annotations.QuerySqlField;
> import org.apache.ignite.configuration.CacheConfiguration;
> import org.apache.ignite.configuration.IgniteConfiguration;
> public class LocalDateTimeChecker {
> // Person POJO with annotations
> public static class Person {
> @QuerySqlField(index = true)
> private int id;
> @QuerySqlField
> private String name;
>
> @QuerySqlField
> private LocalDateTime createdAt;
> public Person() {}
> public Person(int id, String name, LocalDateTime createdAt) {
> this.id = id;
> this.name = name;
> this.createdAt = createdAt;
> }
> // Getters and setters
> public int getId() { return id; }
> public void setId(int id) { this.id = id; }
> public String getName() { return name; }
> public void setName(String name) { this.name = name; }
> public LocalDateTime getCreatedAt() { return createdAt; }
> public void setCreatedAt(LocalDateTime createdAt) { this.createdAt =
> createdAt; }
> }
> public static void main(String[] args) {
> // Configure Ignite
> IgniteConfiguration cfg = new IgniteConfiguration(); //
> Configure cache
> CacheConfiguration<Integer, Person> cacheCfg = new
> CacheConfiguration<>("PersonCache");
> cacheCfg.setIndexedTypes(Integer.class, Person.class);
> cfg.setCacheConfiguration(cacheCfg); // Start Ignite
> try (Ignite ignite = Ignition.start(cfg)) {
> // Get cache
> IgniteCache<Integer, Person> cache =
> ignite.getOrCreateCache(cacheCfg); // Insert data
> LocalDateTime now = LocalDateTime.now();
> cache.put(1, new Person(1, "John Doe", now));
> cache.put(2, new Person(2, "Jane Smith", now.plusDays(1)));
> // Query using custom function
> SqlFieldsQuery query = new SqlFieldsQuery(
> "SELECT id, name, asLocalDateTime(createdAt) FROM Person"
> ); // Execute query and print results with types
> List<List<?>> results = cache.query(query).getAll();
> for (List<?> row : results) {
> System.out.println("Row data:");
> for (Object field : row) {
> System.out.println("Value: " + field +
> ", Type: " + (field != null ?
> field.getClass().getName() : "null"));
> }
> System.out.println("---");
> }
> }
> }
> } {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)