congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
SimpleJpaRepository.findById
Code IndexAdd Tabnine to your IDE (free)

How to use
findById
method
in
org.springframework.data.jpa.repository.support.SimpleJpaRepository

Best Java code snippets using org.springframework.data.jpa.repository.support.SimpleJpaRepository.findById (Showing top 8 results out of 315)

origin: spring-projects/spring-data-jpa

@Transactional
@Override
public void deleteById(ID id) {
  Assert.notNull(id, ID_MUST_NOT_BE_NULL);
  delete(findById(id).orElseThrow(() -> new EmptyResultDataAccessException(
      String.format("No %s entity with id %s exists!", entityInformation.getJavaType(), id), 1)));
}
origin: spring-projects/spring-data-jpa

@Override
public List<T> findAllById(Iterable<ID> ids) {
  Assert.notNull(ids, "The given Iterable of Id's must not be null!");
  if (!ids.iterator().hasNext()) {
    return Collections.emptyList();
  }
  if (entityInformation.hasCompositeId()) {
    List<T> results = new ArrayList<T>();
    for (ID id : ids) {
      findById(id).ifPresent(results::add);
    }
    return results;
  }
  ByIdsSpecification<T> specification = new ByIdsSpecification<T>(entityInformation);
  TypedQuery<T> query = getQuery(specification, Sort.unsorted());
  return query.setParameter(specification.parameter, ids).getResultList();
}
origin: spring-projects/spring-data-jpa

@Override
public boolean existsById(ID id) {
  Assert.notNull(id, ID_MUST_NOT_BE_NULL);
  if (entityInformation.getIdAttribute() == null) {
    return findById(id).isPresent();
  }
  String placeholder = provider.getCountQueryPlaceholder();
  String entityName = entityInformation.getEntityName();
  Iterable<String> idAttributeNames = entityInformation.getIdAttributeNames();
  String existsQuery = QueryUtils.getExistsQueryString(entityName, placeholder, idAttributeNames);
  TypedQuery<Long> query = em.createQuery(existsQuery, Long.class);
  if (!entityInformation.hasCompositeId()) {
    query.setParameter(idAttributeNames.iterator().next(), id);
    return query.getSingleResult() == 1L;
  }
  for (String idAttributeName : idAttributeNames) {
    Object idAttributeValue = entityInformation.getCompositeIdAttributeValue(id, idAttributeName);
    boolean complexIdParameterValueDiscovered = idAttributeValue != null
        && !query.getParameter(idAttributeName).getParameterType().isAssignableFrom(idAttributeValue.getClass());
    if (complexIdParameterValueDiscovered) {
      // fall-back to findById(id) which does the proper mapping for the parameter.
      return findById(id).isPresent();
    }
    query.setParameter(idAttributeName, idAttributeValue);
  }
  return query.getSingleResult() == 1L;
}
origin: xautlx/s2jh4net

/**
 * 基于主键查询单一数据对象
 *
 * @param id
 * @return
 */
@Transactional(readOnly = true)
public Optional<T> findOptionalOne(ID id) {
  return jpaRepository.findById(id);
}
origin: xautlx/s2jh4net

/**
 * 基于主键查询单一数据对象
 *
 * @param id
 * @return
 */
@Transactional(readOnly = true)
public T findOne(ID id) {
  return jpaRepository.findById(id).orElse(null);
}
origin: org.springframework.data/spring-data-jpa

@Transactional
public void deleteById(ID id) {
  Assert.notNull(id, ID_MUST_NOT_BE_NULL);
  delete(findById(id).orElseThrow(() -> new EmptyResultDataAccessException(
      String.format("No %s entity with id %s exists!", entityInformation.getJavaType(), id), 1)));
}
origin: org.springframework.data/spring-data-jpa

public List<T> findAllById(Iterable<ID> ids) {
  Assert.notNull(ids, "The given Iterable of Id's must not be null!");
  if (!ids.iterator().hasNext()) {
    return Collections.emptyList();
  }
  if (entityInformation.hasCompositeId()) {
    List<T> results = new ArrayList<T>();
    for (ID id : ids) {
      findById(id).ifPresent(results::add);
    }
    return results;
  }
  ByIdsSpecification<T> specification = new ByIdsSpecification<T>(entityInformation);
  TypedQuery<T> query = getQuery(specification, Sort.unsorted());
  return query.setParameter(specification.parameter, ids).getResultList();
}
origin: org.springframework.data/spring-data-jpa

public boolean existsById(ID id) {
  Assert.notNull(id, ID_MUST_NOT_BE_NULL);
  if (entityInformation.getIdAttribute() == null) {
    return findById(id).isPresent();
  }
  String placeholder = provider.getCountQueryPlaceholder();
  String entityName = entityInformation.getEntityName();
  Iterable<String> idAttributeNames = entityInformation.getIdAttributeNames();
  String existsQuery = QueryUtils.getExistsQueryString(entityName, placeholder, idAttributeNames);
  TypedQuery<Long> query = em.createQuery(existsQuery, Long.class);
  if (!entityInformation.hasCompositeId()) {
    query.setParameter(idAttributeNames.iterator().next(), id);
    return query.getSingleResult() == 1L;
  }
  for (String idAttributeName : idAttributeNames) {
    Object idAttributeValue = entityInformation.getCompositeIdAttributeValue(id, idAttributeName);
    boolean complexIdParameterValueDiscovered = idAttributeValue != null
        && !query.getParameter(idAttributeName).getParameterType().isAssignableFrom(idAttributeValue.getClass());
    if (complexIdParameterValueDiscovered) {
      // fall-back to findById(id) which does the proper mapping for the parameter.
      return findById(id).isPresent();
    }
    query.setParameter(idAttributeName, idAttributeValue);
  }
  return query.getSingleResult() == 1L;
}
org.springframework.data.jpa.repository.supportSimpleJpaRepositoryfindById

Popular methods of SimpleJpaRepository

  • delete
  • findAll
  • findOne
  • count
  • save
  • readPage
    Reads the given TypedQuery into a Page applying the given Pageable and Specification.
  • exists
  • flush
  • getCountQuery
    Creates a new count query for the given Specification.
  • getQuery
    Creates a TypedQuery for the given Specification and Sort.
  • <init>
    Creates a new SimpleJpaRepository to manage objects of the given JpaEntityInformation.
  • applyQueryHints
  • <init>,
  • applyQueryHints,
  • applyRepositoryMethodMetadata,
  • applySpecificationToCriteria,
  • deleteAll,
  • deleteAllInBatch,
  • deleteInBatch,
  • executeCountQuery,
  • getCountQueryString

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (Timer)
  • getContentResolver (Context)
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • Collectors (java.util.stream)
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JTable (javax.swing)
  • Join (org.hibernate.mapping)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now