Java Code Examples for org.hibernate.Criteria#setProjection()
The following examples show how to use
org.hibernate.Criteria#setProjection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HibernateStorage.java From gsn with GNU General Public License v3.0 | 6 votes |
public long countStreamElement() throws GSNRuntimeException { Transaction tx = null; try { Session session = sf.getCurrentSession(); tx = session.beginTransaction(); Criteria criteria = session.createCriteria(identifier); criteria.setProjection(Projections.rowCount()); List count = criteria.list(); tx.commit(); return (Long) count.get(0); } catch (RuntimeException e) { try { if (tx != null) tx.rollback(); } catch (RuntimeException ex) { logger.error("Couldn't roll back transaction."); } throw e; } }
Example 2
Source File: ContainerStatusDaoImpl.java From kardio with Apache License 2.0 | 6 votes |
@Override public long getCurrentNumberOfContainsers(int envId,String componentIdsStrg, boolean isParentComponents) throws ParseException { List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg); Session session = sessionFactory.openSession(); DetachedCriteria subMaxDate = DetachedCriteria.forClass(ContainerStatusEntity.class); subMaxDate.setProjection(Projections.max("statsDate")); Criteria crtCurrentCont = session.createCriteria(ContainerStatusEntity.class, "contSts"); crtCurrentCont.createCriteria("contSts.component", "component"); crtCurrentCont.add(Property.forName("statsDate").eq(subMaxDate)); DaoUtil.addEnvironmentToCriteria(envId, isParentComponents, comIdList, crtCurrentCont); crtCurrentCont.setProjection(Projections.sum("totalContainer")); long currentNumOfCont = (long) (crtCurrentCont.uniqueResult() == null ? (long)0 : crtCurrentCont.uniqueResult()); session.close(); return currentNumOfCont; }
Example 3
Source File: BaseServiceImpl.java From S-mall-ssh with GNU General Public License v3.0 | 6 votes |
/** * @see BaseService */ @Override public int total(Object... paramAndObjects) { Criteria c= createCriteria(); if(paramAndObjects.length%2 !=0){ return 0; } for (int i=0;i<paramAndObjects.length;i+=2){ if(paramAndObjects[i+1] == null){ c.add(Restrictions.isNull(paramAndObjects[i].toString())); }else{ c.add(Restrictions.eq(paramAndObjects[i].toString(),paramAndObjects[i+1])); } } c.setProjection(Projections.rowCount()); return ((Long)c.uniqueResult()).intValue(); }
Example 4
Source File: DatabaseDao.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
private Criteria createCriteria(final Session session, final Class< ? > clazz, final ReindexSettings settings, final boolean rowCount) { final Criteria criteria = session.createCriteria(clazz); if (rowCount == true) { criteria.setProjection(Projections.rowCount()); } else { if (settings != null) { if (settings.getLastNEntries() != null) { criteria.addOrder(Order.desc("id")).setMaxResults(settings.getLastNEntries()); } String lastUpdateProperty = null; if (AbstractBaseDO.class.isAssignableFrom(clazz) == true) { lastUpdateProperty = "lastUpdate"; } else if (HistoryEntry.class.isAssignableFrom(clazz) == true) { lastUpdateProperty = "timestamp"; } if (lastUpdateProperty != null && settings.getFromDate() != null) { criteria.add(Restrictions.ge(lastUpdateProperty, settings.getFromDate())); } } } return criteria; }
Example 5
Source File: CollectionLogRepositoryImpl.java From AIDR with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public CollectionLogDataResponse getPaginatedDataForCollection(Integer start, Integer limit, Long collectionId) { Criteria countCriteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(CollectionLog.class); countCriteria.add(Restrictions.eq("collectionId", collectionId)); countCriteria.setProjection(Projections.rowCount()); Long count = (Long) countCriteria.uniqueResult(); if (count == 0){ return new CollectionLogDataResponse(Collections.<CollectionLog>emptyList(), count); } Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(CollectionLog.class); criteria.add(Restrictions.eq("collectionId", collectionId)); criteria.setFirstResult(start); criteria.setMaxResults(limit); criteria.addOrder(Order.desc("startDate")); return new CollectionLogDataResponse(criteria.list(), count); }
Example 6
Source File: K8sApiStatusDaoImpl.java From kardio with Apache License 2.0 | 6 votes |
@Override public long getCurrentNumberOfApis(int envId,String componentIdsStrg) throws ParseException { List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg); Session session = sessionFactory.openSession(); DetachedCriteria subMaxDate = DetachedCriteria.forClass(K8sApiStatusEntity.class); subMaxDate.setProjection(Projections.max("statusDate")); Criteria crtCurrenrApi = session.createCriteria(K8sApiStatusEntity.class); crtCurrenrApi.add(Property.forName("statusDate").eq(subMaxDate)); DaoUtil.addEnvironmentToCriteria(envId, comIdList, crtCurrenrApi); crtCurrenrApi.setProjection(Projections.sum("totalApi")); long currentNumberOfApi = (long) (crtCurrenrApi.uniqueResult() == null ? (long)0 : crtCurrenrApi.uniqueResult()); session.close(); return currentNumberOfApi; }
Example 7
Source File: CreditBankDAOImpl.java From computational-economy with GNU General Public License v3.0 | 6 votes |
@Override public CreditBank findRandom(final Currency currency) { Criteria crit = getSession().createCriteria(CreditBankImpl.class); crit.add(Restrictions.eq("primaryCurrency", currency)); crit.setProjection(Projections.rowCount()); final int count = ((Number) crit.uniqueResult()).intValue(); if (0 != count) { final int index = ApplicationContext.getInstance().getRandomNumberGenerator().nextInt(count); crit = getSession().createCriteria(CreditBankImpl.class); crit.add(Restrictions.eq("primaryCurrency", currency)); return (CreditBankImpl) crit.setFirstResult(index).setMaxResults(1).uniqueResult(); } return null; }
Example 8
Source File: TargetDAOImpl.java From webcurator with Apache License 2.0 | 6 votes |
public boolean isNameOk(AbstractTarget aTarget) { Criteria criteria = getSession().createCriteria(AbstractTarget.class); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq("name", aTarget.getName())); if (aTarget instanceof TargetGroup) { criteria.add(Restrictions.eq("objectType", 0)); } if (aTarget instanceof Target) { criteria.add(Restrictions.eq("objectType", 1)); } if( aTarget.getOid() != null) { criteria.add(Restrictions.ne("oid", aTarget.getOid())); } Integer count = (Integer) criteria.uniqueResult(); return count.intValue() == 0; }
Example 9
Source File: ContainerStatusDaoImpl.java From kardio with Apache License 2.0 | 5 votes |
@Override public List<ContainerStatus> getAllContainersOfParent(String startDate, String endDate, int envId, String componentIdsStrg) throws ParseException { final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg); Date sDate = sdf1.parse(startDate); Date eDate = sdf1.parse(endDate); Session session = sessionFactory.openSession(); Criteria containerCriteria = session.createCriteria(ContainerStatusEntity.class, "contSts"); containerCriteria.createCriteria("contSts.component", "component"); containerCriteria.createCriteria("contSts.environment", "environment"); containerCriteria.add(Restrictions.ge("contSts.statsDate", sDate )); containerCriteria.add(Restrictions.le("contSts.statsDate", eDate )); if(envId != 0){ containerCriteria.add(Restrictions.eq("environment.environmentId", envId)); } containerCriteria.add(Restrictions.eq("environment.envLock", 0)); if(comIdList != null && comIdList.size() != 0){ containerCriteria.add(Restrictions.in("component.parentComponent.componentId", comIdList)); } ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.property("component.parentComponent.componentId")); projectionList.add(Projections.property("contSts.statsDate")); projectionList.add(Projections.sum("contSts.totalContainer")); projectionList.add(Projections.groupProperty("component.parentComponent.componentId")); projectionList.add(Projections.groupProperty("contSts.statsDate")); containerCriteria.setProjection(projectionList); @SuppressWarnings("unchecked") List<Object[]> conList = containerCriteria.list(); List<ContainerStatus> contStatusList = DaoUtil.createContainerStatuses(conList); session.close(); return contStatusList; }
Example 10
Source File: AbstractDaoImpl.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public List findAll() { Criteria criteria = getCurrentSession().createCriteria(entityClass); criteria.setProjection(Projections.distinct(Projections.property("id"))); try { List result = criteria.list(); //System.out.println("result = " + result); return result; } catch (HibernateException e) { logger.error("Error in findAll().",e); return null; } }
Example 11
Source File: DutyRosterTurnDaoImpl.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected Collection<String> handleFindCalendars(Long trialDepartmentId, Long staffId, Long trialId, String calendarPrefix, Integer limit) throws Exception { Criteria dutyRosterCriteria = createDutyRosterTurnCriteria("dutyRosterTurn"); Criteria trialCriteria = null; if (trialDepartmentId != null) { trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.LEFT_JOIN); } else if (trialId != null) { trialCriteria = dutyRosterCriteria.createCriteria("trial", CriteriaSpecification.INNER_JOIN); } if (trialDepartmentId != null || trialId != null) { if (trialDepartmentId != null) { trialCriteria.add(Restrictions.or(Restrictions.isNull("dutyRosterTurn.trial"), Restrictions.eq("department.id", trialDepartmentId.longValue()))); } if (trialId != null) { trialCriteria.add(Restrictions.idEq(trialId.longValue())); } } if (staffId != null) { dutyRosterCriteria.add(Restrictions.eq("staff.id", staffId.longValue())); } CategoryCriterion.apply(dutyRosterCriteria, new CategoryCriterion(calendarPrefix, "calendar", MatchMode.START)); dutyRosterCriteria.addOrder(Order.asc("calendar")); dutyRosterCriteria.setProjection(Projections.distinct(Projections.property("calendar"))); CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.DUTY_ROSTER_TURN_CALENDAR_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS, DefaultSettings.DUTY_ROSTER_TURN_CALENDAR_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), dutyRosterCriteria); return dutyRosterCriteria.list(); }
Example 12
Source File: HibernatePagingDao.java From lemon with Apache License 2.0 | 5 votes |
/** * 分页查询函数,使用已设好查询条件与排序的<code>Criteria</code>. * * @param criteria * 条件 * @param pageNo * 当前页号 * @param pageSize * 每页最大记录数 * @return 含总记录数和当前页数据的Page对象. */ @Transactional(readOnly = true) public Page pagedQuery(Criteria criteria, int pageNo, int pageSize) { Assert.notNull(criteria); Assert.isTrue(pageNo >= 1, "pageNo should be eg 1"); Assert.isTrue(criteria instanceof CriteriaImpl); // 先把Projection和OrderBy条件取出来,清空两者来执行Count操作 Projection projection = HibernateUtils.findProjection(criteria); List orderEntries = HibernateUtils.findOrderEntries(criteria); HibernateUtils.setOrderEntries(criteria, Collections.EMPTY_LIST); // 执行查询 Integer totalCount = this.getCount(criteria); // 将之前的Projection和OrderBy条件重新设回去 criteria.setProjection(projection); if (projection == null) { criteria.setResultTransformer(CriteriaSpecification.ROOT_ENTITY); } HibernateUtils.setOrderEntries(criteria, orderEntries); // 返回分页对象 if (totalCount < 1) { return new Page(); } int start = (pageNo - 1) * pageSize; List result = criteria.setFirstResult(start).setMaxResults(pageSize) .list(); Page page = new Page(result, totalCount); page.setPageNo(pageNo); page.setPageSize(pageSize); return page; }
Example 13
Source File: CounterMatrixDaoImpl.java From kardio with Apache License 2.0 | 5 votes |
/** * Function to create criteria for CounterEntity class * @param envId * @param session * @param platform * @return Criteria */ private Criteria createCounterCriteria(final int envId, Session session, String platform) { DetachedCriteria counterSubquery = DetachedCriteria.forClass(CounterMetricEntity.class, "cm") .setProjection(Property.forName("metricDate").max()); Criteria counterCriteria = session.createCriteria(CounterEntity.class, "counter"); counterCriteria.addOrder(Order.asc("counter.position")); Criteria envCounCriteria = counterCriteria.createCriteria("counter.envCounter", "ec"); if(platform != null && !platform.equalsIgnoreCase("All")){ envCounCriteria.add(Restrictions.eq("ec.platform", platform)); } Criteria metricCriteria = envCounCriteria.createCriteria("ec.countMetric", "counterMetric"); counterSubquery.add(Property.forName("ec.envCounterId").eqProperty("cm.envCounterId")); metricCriteria.add(Subqueries.propertyEq("counterMetric.metricDate", counterSubquery)); //metricCriteria.add(Restrictions.le("counterMetric.metricDate", new Date())); counterCriteria.add(Restrictions.eq("counter.delInd", 0)); if(envId != 0) { envCounCriteria.add(Restrictions.eq("environmentId", envId)); } else { envCounCriteria.add(Restrictions.isNull("environmentId")); } counterCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.max("counter.counterName")); projectionList.add(Projections.max("counterMetric.metricDate")); projectionList.add(Projections.sum("counterMetric.metricVal")); projectionList.add(Projections.max("counter.position")); projectionList.add(Projections.property("counter.counterId")); projectionList.add(Projections.groupProperty("counter.counterId")); counterCriteria.setProjection(projectionList); return counterCriteria; }
Example 14
Source File: CollectionRepositoryImpl.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
@Override public Long getRunningCollectionsCount(String terms) { Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class); criteria.setProjection(Projections.projectionList() .add(Projections.property("id"), "id")); LogicalExpression or = Restrictions.or( Restrictions.eq("status", CollectionStatus.RUNNING), Restrictions.eq("status", CollectionStatus.RUNNING_WARNING) ); LogicalExpression or2 = Restrictions.or( or, Restrictions.eq("status", CollectionStatus.INITIALIZING) ); LogicalExpression orAll = Restrictions.or( or2, Restrictions.eq("status", CollectionStatus.WARNING) ); LogicalExpression andAll = Restrictions.and( orAll, Restrictions.ne("status", CollectionStatus.TRASHED) ); criteria.add(andAll); addCollectionSearchCriteria(terms, criteria); ScrollableResults scroll = criteria.scroll(); int i = scroll.last() ? scroll.getRowNumber() + 1 : 0; return Long.valueOf(i); }
Example 15
Source File: HibernateDao.java From jdal with Apache License 2.0 | 5 votes |
/** * Get Page, apply filter if any. * If Filter is a entity model, use Example to create a criteria. * else enable filter by name on session. * @param page with page definitions * @return page of results */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <K> Page<K> getPage(Page<K> page) { List data = null; // try named query Query query = getQuery(page); if (query != null) { data = query.list(); } else { // try filter, example and criteria builders Criteria criteria = getCriteria(page); ResultTransformer rt = ((CriteriaImpl) criteria).getResultTransformer(); criteria.setProjection(Projections.rowCount()); page.setCount(((Long) criteria.uniqueResult()).intValue()); // reset criteria criteria.setProjection(null); criteria.setResultTransformer(rt); // set start index and page size criteria.setFirstResult(page.getStartIndex()) .setMaxResults(page.getPageSize()); applyOrder(page, criteria); // run it criteria.setCacheable(cachePageQueries); data = criteria.list(); } page.setData(data); return page; }
Example 16
Source File: K8sPodsStatusDaoImpl.java From kardio with Apache License 2.0 | 4 votes |
@Override public List<ApiStatus> getPodsStatus(String startDate, String endDate, int envId, String componentIdsStrg, boolean isParentComponents) throws ParseException { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg); Date sDate = sdf.parse(startDate); Date eDate = sdf.parse(endDate); Session session = sessionFactory.openSession(); Criteria containerCriteria = session.createCriteria(K8sPodsContainersEntity.class, "contSts"); containerCriteria.createCriteria("contSts.component", "component"); containerCriteria.add(Restrictions.gt("contSts.statusDate", sDate )); containerCriteria.add(Restrictions.le("contSts.statusDate", eDate )); DaoUtil.addEnvironmentToCriteria(envId, isParentComponents, comIdList, containerCriteria); ProjectionList projectionList= Projections.projectionList(); projectionList.add(Projections.property("component.componentId")); projectionList.add(Projections.property("statusDate")); projectionList.add(Projections.property("totalPods")); projectionList.add(Projections.property("environment.environmentId")); containerCriteria.setProjection(projectionList); @SuppressWarnings("unchecked") List<Object[]> K8sPodsList = containerCriteria.list(); List<ApiStatus> k8sList = new ArrayList<ApiStatus>(); for (Object[] aRow : K8sPodsList) { ApiStatus k8sStatus = new ApiStatus(); Integer comId = (Integer) aRow[0]; k8sStatus.setComponentId(comId); Date statsDate = (Date) aRow[1]; k8sStatus.setStatusDate(statsDate.toString()); Integer totalPods = (Integer)aRow[2]; k8sStatus.setTotalPods(totalPods); Integer environmentId = (Integer)aRow[3]; k8sStatus.setEnvironmentId(environmentId); k8sList.add(k8sStatus); } session.close(); return k8sList; }
Example 17
Source File: CollectionRepositoryImpl.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public List<Collection> getStoppedCollections(Integer start, Integer limit, String terms, String sortColumn, String sortDirection) { Criteria criteriaIds = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class); criteriaIds.setProjection(Projections.projectionList() .add(Projections.property("id"), "id")); LogicalExpression or = Restrictions.or( Restrictions.eq("status", CollectionStatus.STOPPED), Restrictions.eq("status", CollectionStatus.NOT_RUNNING) ); LogicalExpression orAll = Restrictions.or( or, Restrictions.eq("status", CollectionStatus.FATAL_ERROR) ); criteriaIds.add(orAll); addCollectionSearchCriteria(terms, criteriaIds); searchCollectionsAddOrder(sortColumn, sortDirection, criteriaIds); if (start != null) { criteriaIds.setFirstResult(start); } if (limit != null) { criteriaIds.setMaxResults(limit); } List<Integer> ids = criteriaIds.list(); if (ids.size() == 0){ return Collections.emptyList(); } Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.in("id", ids)); searchCollectionsAddOrder(sortColumn, sortDirection, criteria); return criteria.list(); }
Example 18
Source File: DaoUtil.java From kardio with Apache License 2.0 | 4 votes |
public static TpsLatency getCurrentTpsAndLatency(String environment, String componentIdsStrg, boolean isParent, String platform, SessionFactory sessionFactory, EnvironmentDao environmentDao) { Session session = sessionFactory.openSession(); List<Integer> comIdList = convertCSVToList(componentIdsStrg); Criteria crtCurrentCont = session.createCriteria(TpsServiceEntity.class, "tpsLat"); crtCurrentCont.createCriteria("tpsLat.component", "component"); if(environment != null && environment.length() != 0 && !environment.equalsIgnoreCase("all")){ int envId = environmentDao.getEnironmentIdFromName(environment); crtCurrentCont.add(Restrictions.eq("environment.environmentId", envId)); } /** * Adding platform criteria for current TPS & Latency. */ if(platform!=null && !platform.equalsIgnoreCase("All")) crtCurrentCont.add(Restrictions.eq("component.platform", platform)); if (comIdList.size() > 0) { if (isParent) { crtCurrentCont.add(Restrictions.in("component.parentComponent.componentId", comIdList)); } else { crtCurrentCont.add(Restrictions.in("component.componentId", comIdList)); } } ProjectionList projList = Projections.projectionList(); projList.add(Projections.sum("tpsValue")); projList.add(Projections.sum("latencyValue")); crtCurrentCont.setProjection(projList); List<Object[]> curTpsLatList = crtCurrentCont.list(); TpsLatency tpsLat = new TpsLatency(); for (Object[] aRow : curTpsLatList) { if(aRow[0] == null){ continue; } double tpsVal = (double) aRow[0]; double latencyVal = (double) aRow[1]; tpsLat.setTpsValue(tpsVal); tpsLat.setLatencyValue(latencyVal); } session.close(); return tpsLat; }
Example 19
Source File: K8sContainerStatusDaoImpl.java From kardio with Apache License 2.0 | 4 votes |
@Override public List<K8sContainerStatus> getAllContainersOfParent(String startDate, String endDate, int envId, String componentIdsStrg) throws ParseException { final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); List<Integer> comIdList = DaoUtil.convertCSVToList(componentIdsStrg); Date sDate = sdf1.parse(startDate); Date eDate = sdf1.parse(endDate); Session session = sessionFactory.openSession(); Criteria containerCriteria = session.createCriteria(K8sPodsContainersEntity.class, "contSts"); containerCriteria.createCriteria("contSts.component", "component"); containerCriteria.createCriteria("contSts.environment", "environment"); containerCriteria.add(Restrictions.ge("contSts.statusDate", sDate )); containerCriteria.add(Restrictions.le("contSts.statusDate", eDate )); if(envId != 0){ containerCriteria.add(Restrictions.eq("environment.environmentId", envId)); } containerCriteria.add(Restrictions.eq("environment.envLock", 0)); if(comIdList != null && comIdList.size() != 0){ containerCriteria.add(Restrictions.in("component.parentComponent.componentId", comIdList)); } ProjectionList projectionList = DaoUtil.getContainerStatusProjectionList(); containerCriteria.setProjection(projectionList); @SuppressWarnings("unchecked") List<Object[]> conList = containerCriteria.list(); List<K8sContainerStatus> contStatusList = new ArrayList<K8sContainerStatus>(); for (Object[] aRow : conList) { K8sContainerStatus contStatus = new K8sContainerStatus(); Integer comId = (Integer) aRow[0]; contStatus.setComponentId(comId); Date statsDate = (Date) aRow[1]; contStatus.setStatusDate(statsDate.toString()); long totalCont = (long) aRow[2]; contStatus.setTotalContainers(totalCont); contStatusList.add(contStatus); } session.close(); return contStatusList; }
Example 20
Source File: IdentifierPropertyReferencesTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void testCriteriaIdPropertyReferences() { Session s = openSession(); s.beginTransaction(); Person p = new Person( new Long(1), "steve", 123 ); s.save( p ); Order o = new Order( new Long(1), p ); LineItem l = new LineItem( o, "my-product", 2 ); l.setId( "456" ); s.save( o ); s.getTransaction().commit(); s.close(); s = openSession(); s.beginTransaction(); Criteria crit = s.createCriteria( Person.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "id", new Integer(123) ) ); long count = extractCount( crit ); assertEquals( "Person by id prop (non-identifier)", 1, count ); crit = s.createCriteria( Person.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "pk", new Long(1) ) ); count = extractCount( crit ); assertEquals( "Person by pk prop (identifier)", 1, count ); crit = s.createCriteria( Order.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "number", new Long(1) ) ); count = extractCount( crit ); assertEquals( "Order by number prop (named identifier)", 1, count ); crit = s.createCriteria( Order.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "id", new Long(1) ) ); count = extractCount( crit ); assertEquals( "Order by id prop (virtual identifier)", 1, count ); crit = s.createCriteria( LineItem.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "id", "456" ) ); count = extractCount( crit ); assertEquals( "LineItem by id prop (non-identifier", 1, count ); if ( getDialect().supportsRowValueConstructorSyntax() ) { crit = s.createCriteria( LineItem.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "pk", new LineItemPK( o, "my-product" ) ) ); count = extractCount( crit ); assertEquals( "LineItem by pk prop (named composite identifier)", 1, count ); } crit = s.createCriteria( Order.class ); crit.setProjection( Projections.rowCount() ); crit.createAlias( "orderee", "p" ).add( Restrictions.eq( "p.id", new Integer(1) ) ); count = extractCount( crit ); assertEquals( 0, count ); crit = s.createCriteria( Order.class ); crit.setProjection( Projections.rowCount() ); crit.createAlias( "orderee", "p" ).add( Restrictions.eq( "p.pk", new Long(1) ) ); count = extractCount( crit ); assertEquals( 1, count ); crit = s.createCriteria( Order.class ); crit.setProjection( Projections.rowCount() ); crit.createAlias( "orderee", "p" ).add( Restrictions.eq( "p.id", new Integer(123) ) ); count = extractCount( crit ); assertEquals( 1, count ); crit = s.createCriteria( LineItem.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "pk.order.id", new Long(1) ) ); count = extractCount( crit ); assertEquals( 1, count ); crit = s.createCriteria( LineItem.class ); crit.setProjection( Projections.rowCount() ); crit.add( Restrictions.eq( "pk.order.number", new Long(1) ) ); count = extractCount( crit ); assertEquals( 1, count ); s.delete( o ); s.delete( p ); s.getTransaction().commit(); s.close(); }