/**
* Retrieves an entity by its id.
*
* @param id must not be {@literal null}.
* @return the entity with the given id or {@literal Optional#empty()} if none found
* @throws IllegalArgumentException if {@code id} is {@literal null}.
*/Optional<T>findById(ID id);/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#findById(java.io.Serializable)
*/publicOptional<T>findById(ID id){Assert.notNull(id, ID_MUST_NOT_BE_NULL);Class<T> domainType =getDomainClass();if(metadata ==null){returnOptional.ofNullable(em.find(domainType, id));}LockModeType type = metadata.getLockModeType();Map<String,Object> hints =getQueryHints().withFetchGraphs(em).asMap();returnOptional.ofNullable(type ==null? em.find(domainType, id, hints): em.find(domainType, id, type, hints));}
findOne()
/**
* Returns a single entity matching the given {@link Example} or {@literal null} if none was found.
*
* @param example must not be {@literal null}.
* @return a single entity matching the given {@link Example} or {@link Optional#empty()} if none was found.
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the Example yields more than one result.
*/<SextendsT>Optional<S>findOne(Example<S> example);@Overridepublic<SextendsT>Optional<S>findOne(Example<S> example){try{returnOptional.of(getQuery(newExampleSpecification<S>(example, escapeCharacter), example.getProbeType(),Sort.unsorted()).getSingleResult());}catch(NoResultException e){returnOptional.empty();}}
getByOne()
/**
* 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.
*/TgetOne(ID id);@OverridepublicTgetOne(ID id){Assert.notNull(id, ID_MUST_NOT_BE_NULL);return em.getReference(getDomainClass(), id);}@Overridepublic<T>TgetReference(Class<T> entityClass,Object primaryKey){checkOpen();try{returnbyId( entityClass ).getReference((Serializable) primaryKey );}catch(MappingException|TypeMismatchException|ClassCastException e ){throw exceptionConverter.convert(newIllegalArgumentException( e.getMessage(), e ));}catch(RuntimeException e ){throw exceptionConverter.convert( e );}}