org.hibernate.Criteria.createAlias()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(400)

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

Criteria.createAlias介绍

[英]Join an association, assigning an alias to the joined association.

Functionally equivalent to #createAlias(String,String,JoinType) using JoinType#INNER_JOIN for the joinType.
[中]加入关联,为已加入的关联指定别名。
功能上等同于使用JoinType的#内部"JOIN为JoinType创建别名(字符串、字符串、JoinType)。

代码示例

代码示例来源:origin: stackoverflow.com

Criteria c = session.createCriteria(Cat.class);
c.createAlias("mother.kind", "motherKind");
c.addOrder(Order.asc("motherKind.value"));
return c.list();

代码示例来源:origin: stackoverflow.com

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

crit.add(Restrictions.eq("p.elements", portalUsername));

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

@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: kaaproject/kaa

@Override
public List<EndpointGroup> findEndpointGroupsByTopicIdAndAppId(String appId, String topicId) {
 List<EndpointGroup> groups = Collections.emptyList();
 LOG.debug("Searching endpoint group by application id [{}] and topic id [{}]", appId, topicId);
 if (isNotBlank(appId)) {
  Criteria criteria = getCriteria();
  criteria.createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS);
  criteria.createAlias(TOPICS_PROPERTY, TOPIC_ALIAS);
  criteria.add(Restrictions.and(
    Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
    Restrictions.eq(TOPIC_REFERENCE, Long.valueOf(topicId))));
  groups = findListByCriteria(criteria);
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{}] Search result: {}.", appId, Arrays.toString(groups.toArray()));
 } else {
  LOG.debug("[{}] Search result: {}.", appId, groups.size());
 }
 return groups;
}

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

@Override
public EndpointProfileSchema findLatestByAppId(String appId) {
 EndpointProfileSchema latestSchema = null;
 LOG.debug("Searching latest profile schema by application id [{}] ", appId);
 if (isNotBlank(appId)) {
  Criteria criteria = getCriteria().createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS)
    .add(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)))
    .addOrder(Order.desc(VERSION_PROPERTY)).setMaxResults(FIRST);
  latestSchema = findOneByCriteria(criteria);
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{}] Search result: {}.", appId, latestSchema);
 } else {
  LOG.debug("[{}] Search result: {}.", appId, latestSchema != null);
 }
 return latestSchema;
}

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

@Override
public Configuration findLatestActiveBySchemaIdAndGroupId(String schemaId, String groupId) {
 Configuration configuration = null;
 LOG.debug("Searching latest active configuration by configuration schema id [{}] "
     + "and group id [{}]",
   schemaId, groupId);
 if (isNotBlank(schemaId) && isNotBlank(groupId)) {
  Criteria criteria = getCriteria();
  criteria.createAlias(CONFIGURATION_SCHEMA_PROPERTY, CONFIGURATION_SCHEMA_ALIAS);
  criteria.createAlias(ENDPOINT_GROUP_PROPERTY, ENDPOINT_GROUP_ALIAS);
  criteria.add(Restrictions.and(
    Restrictions.eq(ENDPOINT_GROUP_REFERENCE, Long.valueOf(groupId)),
    Restrictions.eq(CONFIGURATION_SCHEMA_REFERENCE, Long.valueOf(schemaId)),
    Restrictions.eq(STATUS_PROPERTY, UpdateStatus.ACTIVE)));
  configuration = findOneByCriteria(criteria);
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", schemaId, groupId, configuration);
 } else {
  LOG.debug("[{},{}] Search result: {}.", schemaId, groupId, configuration != null);
 }
 return configuration;
}

代码示例来源:origin: stackoverflow.com

Criteria criteria = currentSession.createCriteria(Professor.class, "professor");
  criteria.createAlias("professor.students", "student");
  criteria.createAlias("student.assigments", "assigment");
  criteria.add(Restrictions.eqProperty("professor.id", "student.profid"));
  criteria.add(Restrictions.eqProperty("assigment.studentid", "student.profid"));
  criteria.add(Restrictions.eq("id", 2411));
return criteria.list();

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

List<Object[]> result = session.createCriteria( Category.class, "c" ).createAlias( "products", "p" )
    .setProjection(
        Projections.projectionList()
    .setFirstResult( 1 ).setMaxResults( 3 ).list();

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

@Override
 public List<ApplicationEventFamilyMap> findByEcfIdAndVersion(String ecfId, int version) {
  LOG.debug("Searching application event family maps by event class family id [{}] and "
       + "version [{}] ", ecfId, version);
  Criteria criteria = getCriteria();
  criteria.createAlias(ECF_PROPERTY, ECF_ALIAS);
  criteria.add(Restrictions.and(
    Restrictions.eq(ECF_REFERENCE, Long.valueOf(ecfId)),
    Restrictions.eq(VERSION_PROPERTY, version)));
  List<ApplicationEventFamilyMap> maps = findListByCriteria(criteria);
  if (LOG.isTraceEnabled()) {
   LOG.trace("[{},{}] Search result: {}.", ecfId, version, Arrays.toString(maps.toArray()));
  } else {
   LOG.debug("[{},{}] Search result: {}.", ecfId, version, maps.size());
  }
  return maps;
 }
}

代码示例来源:origin: stackoverflow.com

public List<PayoutDetails> getPayoutDetails(AdvisorReportForm advisorReportForm) {
   Criteria criteria = getSession().createCriteria(PayoutDetails.class);
   if (advisorReportForm.getAdvisorId() != null && advisorReportForm.getAdvisorId() > 0) {
     criteria.add(Restrictions.eq("advisorId", advisorReportForm.getAdvisorId().toString()));
   }
   criteria.createAlias("payoutHeader", "header")
       .add(Restrictions.between("header.chequeIssuedDate", advisorReportForm.getFromDate(), advisorReportForm.getToDate()));        
   return criteria.list();
 }

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

.createCriteria( Item.class )
    .addOrder( org.hibernate.criterion.Order.asc( "this.name" ) )
    .createAlias( "this.bids", "i_bid", JoinType.LEFT_OUTER_JOIN )
    .setProjection(
        Projections.projectionList().add( Projections.property( "this.name" ), "item_name" )
criteria.list();

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

@Override
public ConfigurationSchema findLatestByApplicationId(String appId) {
 ConfigurationSchema latestSchema = null;
 LOG.debug("Searching latest configuration schema by application id [{}] ", appId);
 if (isNotBlank(appId)) {
  Criteria criteria = getCriteria().createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS)
    .add(Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)))
    .addOrder(Order.desc(VERSION_PROPERTY))
    .setMaxResults(FIRST);
  latestSchema = findOneByCriteria(criteria);
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{}] Search result: {}.", appId, latestSchema);
 } else {
  LOG.debug("[{}] Search result: {}.", appId, latestSchema != null);
 }
 return latestSchema;
}

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

@Override
public Configuration findInactiveBySchemaIdAndGroupId(String schemaId, String groupId) {
 Configuration configuration = null;
 LOG.debug("Searching inactive configuration by configuration schema id [{}] and "
     + "group id [{}] ",
   schemaId, groupId);
 if (isNotBlank(schemaId) && isNotBlank(groupId)) {
  Criteria criteria = getCriteria();
  criteria.createAlias(CONFIGURATION_SCHEMA_PROPERTY, CONFIGURATION_SCHEMA_ALIAS);
  criteria.createAlias(ENDPOINT_GROUP_PROPERTY, ENDPOINT_GROUP_ALIAS);
  criteria.add(Restrictions.and(
    Restrictions.eq(ENDPOINT_GROUP_REFERENCE, Long.valueOf(groupId)),
    Restrictions.eq(CONFIGURATION_SCHEMA_REFERENCE, Long.valueOf(schemaId)),
    Restrictions.eq(STATUS_PROPERTY, UpdateStatus.INACTIVE)));
  configuration = findOneByCriteria(criteria);
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", schemaId, groupId, configuration);
 } else {
  LOG.debug("[{},{}] Search result: {}.", schemaId, groupId, configuration != null);
 }
 return configuration;
}

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

.createAlias("student", "s")
.createAlias("course", "c")
.add( Restrictions.isNotEmpty("s.enrolments") )
.setCacheable(true)
.setReadOnly( true )
.list();
.createAlias("student", "s")
.createAlias("course", "c")
.setReadOnly( true )
.add( Restrictions.isNotEmpty("s.enrolments") )
.setCacheable(true)
.setReadOnly( true )
.list();
.createAlias("student", "s")
.createAlias("course", "c")
.add( Restrictions.isNotEmpty("s.enrolments") )
.setCacheable(true)
.list();

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

@Override
public Configuration findLatestDeprecated(String schemaId, String groupId) {
 Configuration configuration = null;
 LOG.debug("Searching latest deprecated configurations by configuration schema id [{}] "
     + "and group id [{}] ",
   schemaId, groupId);
 if (isNotBlank(schemaId) && isNotBlank(groupId)) {
  Criteria criteria = getCriteria();
  criteria.createAlias(CONFIGURATION_SCHEMA_PROPERTY, CONFIGURATION_SCHEMA_ALIAS);
  criteria.createAlias(ENDPOINT_GROUP_PROPERTY, ENDPOINT_GROUP_ALIAS);
  criteria.add(Restrictions.and(
    Restrictions.eq(ENDPOINT_GROUP_REFERENCE, Long.valueOf(groupId)),
    Restrictions.eq(CONFIGURATION_SCHEMA_REFERENCE, Long.valueOf(schemaId)),
    Restrictions.eq(STATUS_PROPERTY, UpdateStatus.DEPRECATED)));
  criteria.addOrder(Order.desc(SEQUENCE_NUMBER_PROPERTY)).setMaxResults(FIRST);
  configuration = findOneByCriteria(criteria);
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", schemaId, groupId, configuration);
 } else {
  LOG.debug("[{},{}] Search result: {}.", schemaId, groupId, configuration != null);
 }
 return configuration;
}

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

@Override
public CtlSchema findLatestByMetaInfoId(String metaInfoId) {
 CtlSchema latestSchema = null;
 LOG.debug("Searching latest version of ctl schema by meta info id [{}]",
   metaInfoId);
 if (isNotBlank(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.desc(CTL_SCHEMA_VERSION))
    .setMaxResults(FIRST);
  latestSchema = findOneByCriteria(criteria);
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{}] Search result: [{}].", metaInfoId, latestSchema);
 } else {
  LOG.debug("[{}] Search result: [{}].", metaInfoId, latestSchema != null);
 }
 return latestSchema;
}

相关文章