org.hibernate.criterion.Restrictions.eq()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(230)

本文整理了Java中org.hibernate.criterion.Restrictions.eq方法的一些代码示例,展示了Restrictions.eq的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Restrictions.eq方法的具体详情如下:
包路径:org.hibernate.criterion.Restrictions
类名称:Restrictions
方法名:eq

Restrictions.eq介绍

[英]Apply an "equal" constraint to the named property
[中]对命名属性应用“相等”约束

代码示例

代码示例来源: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: 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: 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: hibernate/hibernate-orm

Criteria criteria = session.createCriteria( Seller.class, "s" );
criteria.createCriteria(
    "s.soldTo",
    "c",
    JoinType.INNER_JOIN,
    Restrictions.eq( "name", "join-table-customer1" )
);
criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
@SuppressWarnings("unchecked")
List<Seller> results = criteria.list();
assertTrue( results.size() == 1 );
assertTrue( results.contains( seller1 ) );
criteria = session.createCriteria( Seller.class, "s" );
criteria.createCriteria(
    "s.soldTo",
    "c",
    JoinType.INNER_JOIN,
    Restrictions.eq( "name", "join-table-customer2" )
);
criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
List<Seller> results2 = criteria.list();
assertTrue( results2.size() == 2 );
assertTrue( results2.contains( seller1 ) );

代码示例来源:origin: kaaproject/kaa

@Override
public LogSchema findLatestLogSchemaByAppId(String applicationId) {
 LOG.debug("Searching latest log schema  by application id [{}]", applicationId);
 LogSchema logSchema = null;
 if (isNotBlank(applicationId)) {
  Criteria criteria = getCriteria();
  criteria.createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS);
  Criterion criterion = Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(applicationId));
  logSchema = (LogSchema) criteria.add(criterion).addOrder(Order.desc(VERSION_PROPERTY))
    .setMaxResults(FIRST).uniqueResult();
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{}] Search result: {}.", applicationId, logSchema);
 } else {
  LOG.debug("[{}] Search result: {}.", applicationId, logSchema != null);
 }
 return logSchema;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

criteria.add(Restrictions.eq("hidden", false));
      current.add(Restrictions.eq(key, convertType(param[1], OptionFilterParamType.valueOf(param[2]))));
List results = criteria.list();
String[][] enumerationValues = new String[results.size()][2];
int j = 0;

代码示例来源: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: 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 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();
}

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use PassThroughTransformer by default
    return s.createCriteria( Enrolment.class )
        .setProjection( Projections.property( "student" ) )
        .add( Restrictions.eq( "studentNumber", Long.valueOf( yogiExpected.getStudentNumber() ) ) );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

Criteria criteria = session.createCriteria( Customer.class, "c" );
criteria.createCriteria(
    "c.boughtFrom",
    "s",
    JoinType.INNER_JOIN,
    Restrictions.eq( "name", "mappedby-seller1" )
);
criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
@SuppressWarnings("unchecked")
List<Customer> results = criteria.list();
assertTrue( results.size() == 2 );
assertTrue( results.contains( customer1 ) );
criteria = session.createCriteria( Customer.class, "c" );
criteria.createCriteria(
    "c.boughtFrom",
    "s",
    JoinType.INNER_JOIN,
    Restrictions.eq( "name", "mappedby-seller2" )
);
criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
@SuppressWarnings("unchecked")
List<Customer> results2 = criteria.list();
assertTrue( results2.size() == 2 );
assertFalse( results2.contains( customer1 ) );

代码示例来源:origin: kaaproject/kaa

criteria.createAlias(ENDPOINT_GROUP_PROPERTY, ENDPOINT_GROUP_ALIAS);
Criterion crit = Restrictions.and(
  Restrictions.eq(ENDPOINT_GROUP_REFERENCE, Long.valueOf(groupId)),
  buildEqIdCriterion(ENDPOINT_PROFILE_SCHEMA_REFERENCE, endpointProfileSchemaId),
  buildEqIdCriterion(SERVER_PROFILE_SCHEMA_REFERENCE, serverProfileSchemaId),
  Restrictions.eq(STATUS_PROPERTY, UpdateStatus.DEPRECATED));
filter = (ProfileFilter) criteria.add(crit).addOrder(Order.desc(SEQUENCE_NUMBER_PROPERTY))
    .setMaxResults(FIRST).uniqueResult();

代码示例来源:origin: gocd/gocd

@Override
  public Object doInTransaction(TransactionStatus status) {
    PropertyProjection pipelineName = Projections.property("pipelineName");
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(PipelineState.class).setProjection(pipelineName).add(
        Restrictions.eq("locked", true));
    criteria.setCacheable(false);
    List<String> list = criteria.list();
    return list;
  }
});

代码示例来源: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 username or email.
 *
 * @param usernameOrMail the username or email of user
 * @return user
 */
public User findByUsernameOrMail(String usernameOrMail) {
 Criteria criteria = getCriteria();
 Criterion usernameCriterion = Restrictions.eq(USERNAME_PROPERTY, usernameOrMail);
 Criterion mailCriterion = Restrictions.eq(MAIL_PROPERTY, usernameOrMail);
 criteria.add(Restrictions.or(usernameCriterion, mailCriterion));
 return (User) criteria.uniqueResult();
}

代码示例来源:origin: hibernate/hibernate-orm

protected Criteria getCriteria(Session s) {
    // should use PassThroughTransformer by default
    return s.createCriteria( Enrolment.class, "e" )
        .setProjection( Projections.property( "e.semester" ) )
        .add( Restrictions.eq( "e.studentNumber", shermanEnrolmentExpected.getStudentNumber() ) );
  }
};

代码示例来源:origin: hibernate/hibernate-orm

s.getTransaction().begin();
Criteria rootCriteria = s.createCriteria( Order.class, "o" );
Criteria subCriteria = rootCriteria.createCriteria(
    "orderLines",
    Restrictions.or(
        Restrictions.isNull( "ol.articleId" ),		  // Allow null
        Restrictions.eq( "ol.articleId", "1000" )
List orders = rootCriteria.setResultTransformer( Criteria.ALIAS_TO_ENTITY_MAP ).list();

代码示例来源:origin: gocd/gocd

public Users findNotificationSubscribingUsers() {
  return (Users) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class);
    criteria.setCacheable(true);
    criteria.add(Restrictions.isNotEmpty("notificationFilters"));
    criteria.add(Restrictions.eq("enabled", true));
    return new Users(criteria.list());
  });
}

代码示例来源:origin: gocd/gocd

@Override
public JobAgentMetadata load(final Long jobId) {
  return (JobAgentMetadata) transactionTemplate.execute((TransactionCallback) transactionStatus -> sessionFactory.getCurrentSession()
      .createCriteria(JobAgentMetadata.class)
      .add(Restrictions.eq("jobId", jobId))
      .setCacheable(true).uniqueResult());
}

相关文章