From cdbc832068ae4e2c88e48c9419a4a689cb7bc6ba Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 12 Jul 2018 15:27:36 +0200 Subject: [PATCH] DATAES-471 - Adapt object property access behavior after changes in Spring Data Commons. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes made for Spring Data Commons result in final fields being rejected for manipulation unless there's a wither method available on the object at hand. Unfortunately adapting Spring Data Elasticsearch to support that doesn't work easily as it requires breaking changes to ElasticsearchTemplate as most of the methods assume parameters being handed to be mutable, see the implementation of SimpleElasticsearchRepository.save(…) for instance. We now mitigate the problem, by enforcing the BeanWrapperPropertyAccessor being used and treating all properties as mutable. Related tickets: DATACMNS-1322. --- .../SimpleElasticsearchPersistentEntity.java | 14 ++++++++++++++ .../SimpleElasticsearchPersistentProperty.java | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java index 9be82f990..cefe8f6b9 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentEntity.java @@ -28,7 +28,9 @@ import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Parent; import org.springframework.data.elasticsearch.annotations.Setting; import org.springframework.data.mapping.MappingException; +import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.mapping.model.BasicPersistentEntity; +import org.springframework.data.mapping.model.PersistentPropertyAccessorFactory; import org.springframework.data.util.TypeInformation; import org.springframework.expression.Expression; import org.springframework.expression.ParserContext; @@ -195,4 +197,16 @@ public class SimpleElasticsearchPersistentEntity extends BasicPersistentEntit this.scoreProperty = property; } } + + /* + * (non-Javadoc) + * @see org.springframework.data.mapping.model.BasicPersistentEntity#setPersistentPropertyAccessorFactory(org.springframework.data.mapping.model.PersistentPropertyAccessorFactory) + */ + @Override + public void setPersistentPropertyAccessorFactory(PersistentPropertyAccessorFactory factory) { + + // Do nothing to avoid the usage of ClassGeneratingPropertyAccessorFactory for now + // DATACMNS-1322 switches to proper immutability behavior which Spring Data Elasticsearch + // cannot yet implement + } } diff --git a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java index c10318ee0..3aafc5ab5 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/mapping/SimpleElasticsearchPersistentProperty.java @@ -85,4 +85,13 @@ public class SimpleElasticsearchPersistentProperty extends public boolean isScoreProperty() { return isScore; } + + /* + * (non-Javadoc) + * @see org.springframework.data.mapping.model.AbstractPersistentProperty#isImmutable() + */ + @Override + public boolean isImmutable() { + return false; + } }