Tabnine Logo
Criteria.add
Code IndexAdd Tabnine to your IDE (free)

How to use
add
method
in
org.hibernate.Criteria

Best Java code snippets using org.hibernate.Criteria.add (Showing top 20 results out of 1,818)

Refine searchRefine arrow

  • Restrictions.eq
  • Criteria.list
  • Session.createCriteria
  • SessionFactory.getCurrentSession
  • Criteria.uniqueResult
  • Criteria.createAlias
origin: stackoverflow.com

 Criteria c = session.createCriteria(CountryDTO.class);
c.add(Restrictions.eq("type", type));
c.add(status == null ? Restrictions.isNull("status") : Restrictions.eq("status", status));
List result = c.list();
origin: iluwatar/java-design-patterns

 @Override
 public Spell findByName(String name) {
  Transaction tx = null;
  Spell result = null;
  try (Session session = getSessionFactory().openSession()) {
   tx = session.beginTransaction();
   Criteria criteria = session.createCriteria(persistentClass);
   criteria.add(Restrictions.eq("name", name));
   result = (Spell) criteria.uniqueResult();
   tx.commit();
  } catch (Exception e) {
   if (tx != null) {
    tx.rollback();
   }
   throw e;
  }
  return result;
 }
}
origin: stackoverflow.com

 Criteria crit = getSession().createCriteria(Discussion.class);
crit.createAlias("participants", "p");

crit.add(Restrictions.eq("p.elements", portalUsername));
origin: kaaproject/kaa

/**
 * Check if authority exists.
 *
 * @param authority the authority
 * @return true if authority exists
 */
public boolean isAuthorityExists(String authority) {
 Criteria criteria = getSession().createCriteria(Authority.class);
 criteria.add(Restrictions.eq(AUTHORITY_PROPERTY, authority));
 List<Authority> resultList = criteria.list();
 return !resultList.isEmpty();
}
origin: spring-projects/spring-framework

@Override
@SuppressWarnings({"unchecked", "deprecation"})
public <T> List<T> findByExample(
    @Nullable final String entityName, final T exampleEntity, final int firstResult, final int maxResults)
    throws DataAccessException {
  Assert.notNull(exampleEntity, "Example entity must not be null");
  return nonNull(executeWithNativeSession((HibernateCallback<List<T>>) session -> {
    Criteria executableCriteria = (entityName != null ?
        session.createCriteria(entityName) : session.createCriteria(exampleEntity.getClass()));
    executableCriteria.add(Example.create(exampleEntity));
    prepareCriteria(executableCriteria);
    if (firstResult >= 0) {
      executableCriteria.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
      executableCriteria.setMaxResults(maxResults);
    }
    return executableCriteria.list();
  }));
}
origin: gocd/gocd

  @Override
  public Object doInTransaction(TransactionStatus transactionStatus) {
    return sessionFactory.getCurrentSession()
        .createCriteria(PipelineState.class)
        .add(Restrictions.eq("pipelineName", pipelineName))
        .setCacheable(false).uniqueResult();
  }
});
origin: kaaproject/kaa

/**
 * Find user by username.
 *
 * @param userName the username of user
 * @return user
 */
public User findByUserName(String userName) {
 Criteria criteria = getCriteria();
 criteria.add(Restrictions.eq(USERNAME_PROPERTY, userName));
 return (User) criteria.uniqueResult();
}
origin: hibernate/hibernate-orm

  protected Criteria getCriteria(Session s) {
    // should use RootEntityTransformer by default
    return s.createCriteria( Student.class, "s" )
        .add( Restrictions.eq( "studentNumber", shermanExpected.getStudentNumber() ) );
    }
};
origin: kaaproject/kaa

@Override
public boolean validateName(String tenantId, String ecfId, String name) {
 LOG.debug("Validating by tenant id [{}], ecf id [{}], name [{}]", tenantId, ecfId, name);
 Criteria criteria = getCriteria();
 criteria.createAlias(TENANT_PROPERTY, TENANT_ALIAS);
 criteria.add(Restrictions.and(
   Restrictions.eq(TENANT_REFERENCE, Long.valueOf(tenantId)),
   Restrictions.eq(NAME_PROPERTY, name)));
 if (isNotBlank(ecfId)) {
  criteria = criteria.add(Restrictions.ne(ID_PROPERTY, Long.valueOf(ecfId)));
 }
 List<EventClassFamily> eventClassFamilies = findListByCriteria(criteria);
 boolean result = eventClassFamilies == null || eventClassFamilies.isEmpty();
 LOG.debug("[{},{},{}] Validating result: {}", tenantId, ecfId, name, result);
 return result;
}
origin: hibernate/hibernate-orm

@Test
public void shouldNotRetrieveSubSubSubEntityWithCriteria() {
  session = openSession();
  try {
    SubSubSubEntity loaded = (SubSubSubEntity) session.createCriteria( SubSubSubEntity.class )
        .add( Restrictions.idEq( subSubEntityId ) )
        .uniqueResult();
    assertNull( loaded );
  }
  finally {
    session.close();
  }
}
origin: stackoverflow.com

 Criteria crit = session.createCriteria(Person.class);
crit.add( Restrictions.isNotNull("birthDate"));
crit.add( Restrictions.eq("isStudent", true));
crit.setProjection(Projections.rowCount());
Integer count = (Integer)crit.uniqueResult();
origin: stackoverflow.com

Criteria criteria=session.createCriteria(Student.class);
  criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
  criteria.add(Restrictions.ne("enquiryStatus", ENQUIRY.JOINED));
  criteria.setMaxResults(10);
  criteria.setFirstResult((paginate.getStartIndex()-1)*10);
  List<Student> students = criteria.list();
 criteria.setProjection(null);
 criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
 Long resultCount = (Long)criteria.uniqueResult();
origin: kaaproject/kaa

protected List<T> findListByCriterionWithAlias(String path, String alias,
                        JoinType type, Criterion criterion) {
 String className = getSimpleClassName();
 LOG.trace("Searching {} entities by criterion [{}] ", className, criterion);
 Criteria criteria = getCriteria();
 if (type == null) {
  criteria.createAlias(path, alias);
 } else {
  criteria.createAlias(path, alias, type);
 }
 criteria.add(criterion);
 List<T> resultList = criteria.list();
 if (resultList == null) {
  resultList = Collections.emptyList();
 }
 return resultList;
}
origin: kaaproject/kaa

protected T findOneByCriterionWithAlias(String path, String alias, Criterion criterion) {
 String className = getSimpleClassName();
 LOG.trace("Searching {} entity by criterion [{}] ", className, criterion);
 Criteria criteria = getCriteria();
 criteria.createAlias(path, alias);
 criteria.add(criterion);
 return (T) criteria.uniqueResult();
}
origin: hibernate/hibernate-orm

private Criteria getCriteria(Session s) {
  Criteria crit = s.createCriteria( A.class, "anAlias" );
  crit.add( Restrictions.naturalId().set( "name", "name1" ) );
  crit.setFlushMode( FlushMode.COMMIT );
  crit.setCacheable( true );
  return crit;
}
origin: gocd/gocd

public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
  List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariable.class).add(Restrictions.eq("entityId", entityId)).add(
        Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
    criteria.setCacheable(true);
    return criteria.list();
  });
  return new EnvironmentVariables(result);
}
origin: kaaproject/kaa

@Override
public List<CtlSchema> findAllByMetaInfoId(String metaInfoId) {
 LOG.debug("Searching available version of ctl schema by meta info id [{}]", metaInfoId);
 Criteria criteria = getCriteria()
   .createAlias(CTL_SCHEMA_META_INFO_PROPERTY, CTL_SCHEMA_META_INFO_ALIAS)
   .add(Restrictions.eq(CTL_SCHEMA_META_INFO_ALIAS_ID, Long.valueOf(metaInfoId)))
   .addOrder(Order.asc(CTL_SCHEMA_VERSION));
 List<CtlSchema> schemas = findListByCriteria(criteria);
 if (LOG.isTraceEnabled()) {
  LOG.trace("Search result: [{}].", Arrays.toString(schemas.toArray()));
 } else {
  LOG.debug("Search result: [{}].", schemas.size());
 }
 return schemas;
}
origin: hibernate/hibernate-orm

  @Test
  public void testEnablingJoinFetchProfileAgainstSelfReferentialAssociation() {
    Session s = openSession();
    s.beginTransaction();
    s.enableFetchProfile( Employee.FETCH_PROFILE_TREE );
    s.createCriteria( Employee.class )
        .add( Restrictions.isNull( "manager" ) )
        .list();
    s.getTransaction().commit();
    s.close();
  }
}
origin: gocd/gocd

@Override
public VersionInfo findByComponentName(final String name) {
  return (VersionInfo) transactionTemplate.execute((TransactionCallback) transactionStatus -> sessionFactory.getCurrentSession()
      .createCriteria(VersionInfo.class)
      .add(Restrictions.eq("componentName", name))
      .setCacheable(true).uniqueResult());
}
origin: kaaproject/kaa

/**
 * Find user by password reset hash.
 *
 * @param passwordResetHash the password reset hash
 * @return user
 */
public User findByPasswordResetHash(String passwordResetHash) {
 Criteria criteria = getCriteria();
 criteria.add(Restrictions.eq(PASSWORD_RESET_HASH_PROPERTY, passwordResetHash));
 return (User) criteria.uniqueResult();
}
org.hibernateCriteriaadd

Javadoc

Add a Criterion to constrain the results to be retrieved.

Popular methods of Criteria

  • list
    Get the results.
  • uniqueResult
    Convenience method to return a single instance that matches the query, or null if the query returns
  • addOrder
    Add an Order to the result set.
  • setProjection
    Used to specify that the query results will be a projection (scalar in nature). Implicitly specifies
  • setMaxResults
    Set a limit upon the number of objects to be retrieved.
  • setFirstResult
    Set the first result to be retrieved.
  • setResultTransformer
    Set a strategy for handling the query results. This determines the "shape" of the query result.
  • createAlias
    Join an association using the specified join-type, assigning an alias to the joined association. The
  • createCriteria
    Create a new Criteria, "rooted" at the associated entity, using the specified join type.
  • setFetchMode
    Specify an association fetching strategy for an association or a collection of values.
  • setCacheable
    Enable caching of this query result, provided query caching is enabled for the underlying session fa
  • setFetchSize
    Set a fetch size for the underlying JDBC query.
  • setCacheable,
  • setFetchSize,
  • scroll,
  • setLockMode,
  • setReadOnly,
  • setCacheRegion,
  • setTimeout,
  • setCacheMode,
  • setFlushMode

Popular in Java

  • Reading from database using SQL prepared statement
  • runOnUiThread (Activity)
  • setContentView (Activity)
  • getSystemService (Context)
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Collectors (java.util.stream)
  • JButton (javax.swing)
  • JFileChooser (javax.swing)
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top Vim plugins
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