diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java index 3cd2b165a..5d8afb268 100644 --- a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java @@ -32,6 +32,7 @@ import org.springframework.data.repository.query.QueryByExampleExecutor; * @author Christoph Strobl * @author Mark Paluch * @author Sander Krabbenborg + * @author Jesse Wouters */ @NoRepositoryBean public interface JpaRepository extends PagingAndSortingRepository, QueryByExampleExecutor { @@ -131,9 +132,23 @@ public interface JpaRepository extends PagingAndSortingRepository, * @param id must not be {@literal null}. * @return a reference to the entity with the given identifier. * @see EntityManager#getReference(Class, Object) for details on when an exception is thrown. + * @deprecated use {@link JpaRepository#getById(ID)} instead. */ + @Deprecated T getOne(ID id); + /** + * Returns a reference to the entity with the given identifier. Depending on how the JPA persistence provider is + * implemented this is very likely to always return an instance and throw an + * {@link javax.persistence.EntityNotFoundException} on first access. Some of them will reject invalid identifiers + * immediately. + * + * @param id must not be {@literal null}. + * @return a reference to the entity with the given identifier. + * @see EntityManager#getReference(Class, Object) for details on when an exception is thrown. + */ + T getById(ID id); + /* * (non-Javadoc) * @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example) 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 1ae36e328..2f3af6f25 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 @@ -74,6 +74,7 @@ import org.springframework.util.Assert; * @author David Madden * @author Moritz Becker * @author Sander Krabbenborg + * @author Jesse Wouters * @param the type of the entity to handle * @param the type of the entity's identifier */ @@ -323,6 +324,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation