AbstractHibernateCurator { @Transactional public boolean exists(Serializable id) { boolean doesExists = false; String columnName = getPrimaryKeyName(); if (columnName != null) { CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder(); CriteriaQuery<Long> query = builder.createQuery(Long.class); query.select(builder.count(query.from(entityType))); Root<E> root = query.from(entityType); query.where(builder.equal(root.get(columnName), id)); if (this.getEntityManager().createQuery(query).getSingleResult() > 0) { doesExists = true; } } return doesExists; } AbstractHibernateCurator(Class<E> entityType); Class<E> entityType(); int getInBlockSize(); int getCaseBlockSize(); int getBatchBlockSize(); int getQueryParameterLimit(); E getSingleResult(TypedQuery<E> query); void enableFilter(String filterName, String parameterName, Object value); void enableFilterList(String filterName, String parameterName, Collection value); @Transactional E secureGet(Serializable id); @Transactional E get(Serializable id); @Transactional boolean exists(Serializable id); String getPrimaryKeyName(); @Transactional E create(E entity); @Transactional E create(E entity, boolean flush); CandlepinQuery<E> listAll(); CandlepinQuery<E> listAllByIds(Collection<? extends Serializable> ids); @SuppressWarnings("unchecked") @Transactional Page<List<E>> listAll(PageRequest pageRequest, boolean postFilter); @SuppressWarnings("unchecked") @Transactional Page<List<E>> listAll(PageRequest pageRequest); @SuppressWarnings("unchecked") Page<ResultIterator<E>> paginateResults(CandlepinQuery<E> query, PageRequest pageRequest); @SuppressWarnings("unchecked") @Transactional List<E> listByCriteria(Criteria query); @Transactional List<E> listByCriteria(CriteriaQuery<E> query); @SuppressWarnings("unchecked") @Transactional Page<List<E>> listByCriteria(Criteria query, PageRequest pageRequest, boolean postFilter); @SuppressWarnings("unchecked") @Transactional Page<List<E>> listByCriteria(Criteria c, PageRequest pageRequest); @Transactional Page<List<E>> listByCriteria(Root<E> root, CriteriaQuery<E> criteria, PageRequest pageRequest,
        int maxRecords); @Transactional void delete(E entity); @Transactional void bulkDelete(Collection<E> entities); void detach(E entity); void batchDetach(Collection<E> entities); @Transactional void bulkDeleteTransactional(Collection<E> entities); @Transactional E merge(E entity); @Transactional E saveOrUpdate(E entity); void flush(); void clear(); Session currentSession(); Session openSession(); EntityManager getEntityManager(); EntityTransaction getTransaction(); org.candlepin.util.Transactional<O> transactional(
        org.candlepin.util.Transactional.Action<O> action); @Transactional Collection<E> saveAll(Collection<E> entities, boolean flush, boolean evict); Collection<E> updateAll(Collection<E> entities, boolean flush, boolean evict); Iterable<E> saveOrUpdateAll(Iterable<E> entities, boolean flush, boolean evict); Collection<E> mergeAll(Collection<E> entities, boolean flush); void refresh(Iterable<E> entities); void refresh(E... entities); E evict(E entity); void evictAll(Iterable<E> collection); List<E> takeSubList(PageRequest pageRequest, List<E> results); Collection<E> lock(Iterable<E> entities); Collection<E> lock(E... entities); E lock(E entity); E lock(E entity, LockModeType lockMode); E lockAndLoad(Serializable id); Collection<E> lockAndLoad(Iterable<? extends Serializable> ids);  }
@Test public void testExists() { Owner owner = this.createOwner("ownerPrimaryKey", "owner-1"); Environment environment = this.createEnvironment(owner, "SomeId", "fooBar", null, null, null); assertTrue(this.testOwnerCurator.exists(owner.getId())); assertFalse(this.testOwnerCurator.exists("randomOwnerId")); assertTrue(this.environmentCurator.exists(environment.getId())); assertFalse(this.environmentCurator.exists("randomEnvId")); }