diff --git a/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java b/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java index 93a50398e..b478723cb 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java @@ -46,6 +46,7 @@ import org.springframework.util.Assert; * @author Mark Paluch * @author Christoph Strobl * @author Jens Schauder + * @author Stefan Fussenegger */ public class JpaRepositoryFactory extends RepositoryFactorySupport { @@ -87,8 +88,11 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { @Override protected Object getTargetRepository(RepositoryInformation information) { - SimpleJpaRepository repository = getTargetRepository(information, entityManager); - repository.setRepositoryMethodMetadata(crudMethodMetadataPostProcessor.getCrudMethodMetadata()); + Object repository = getTargetRepository(information, entityManager); + if (repository instanceof RepositoryMethodMetadataAware) { + ((RepositoryMethodMetadataAware) repository) + .setRepositoryMethodMetadata(crudMethodMetadataPostProcessor.getCrudMethodMetadata()); + } return repository; } @@ -101,8 +105,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport { * @param entityManager * @return */ - protected SimpleJpaRepository getTargetRepository( - RepositoryInformation information, EntityManager entityManager) { + protected Object getTargetRepository(RepositoryInformation information, EntityManager entityManager) { JpaEntityInformation entityInformation = getEntityInformation(information.getDomainType()); diff --git a/src/main/java/org/springframework/data/jpa/repository/support/RepositoryMethodMetadataAware.java b/src/main/java/org/springframework/data/jpa/repository/support/RepositoryMethodMetadataAware.java new file mode 100644 index 000000000..fdd6f1baf --- /dev/null +++ b/src/main/java/org/springframework/data/jpa/repository/support/RepositoryMethodMetadataAware.java @@ -0,0 +1,30 @@ +/* + * Copyright 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jpa.repository.support; + +import org.springframework.data.jpa.repository.support.CrudMethodMetadata; + +/** + * implemented by {@link org.springframework.data.jpa.repository.JpaRepository} implementations requiring + * {@link CrudMethodMetadata} + * + * @author Stefan Fussenegger + */ +public interface RepositoryMethodMetadataAware { + + void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata); + +} diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 63919bd11..5b29661bd 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -67,12 +67,14 @@ import org.springframework.util.Assert; * @author Thomas Darimont * @author Mark Paluch * @author Christoph Strobl + * @author Stefan Fussenegger * @param the type of the entity to handle * @param the type of the entity's identifier */ @Repository @Transactional(readOnly = true) -public class SimpleJpaRepository implements JpaRepository, JpaSpecificationExecutor { +public class SimpleJpaRepository + implements JpaRepository, JpaSpecificationExecutor, RepositoryMethodMetadataAware { private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null!";