Ejemplo n.º 1
0
  public Object getAggregateFunctionResult() {
    Session hSession = (Session) entityManager.getDelegate();
    Criteria criteria = hSession.createCriteria(Book.class);
    Object returnObj = 0;

    //		criteria.setProjection(Projections.avg("price"));
    criteria.setProjection(Projections.max("price"));
    List<Book> books = criteria.list();
    //		criteria.setProjection((Projection)Property.forName("name")).
    //		setProjection((Projection)Property.forName("publishedDate"));
    System.out.println("[Criteria] = " + criteria.toString());
    returnObj = books;
    return returnObj;
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  public List<Book> criteriaSearch() {
    List<Book> resultEntities = null;
    Session hSession = (Session) entityManager.getDelegate();
    Criteria criteria = hSession.createCriteria(Book.class);

    /*Equal */
    //		criteria.add(Restrictions.eq("name", "Spring 3").ignoreCase());

    /*LIKE , Between - Integer*/
    //		criteria.add(Restrictions.like("name", "%Hibernate%")).
    //		add(Restrictions.between("price", new Integer(10), new Integer(40)));

    /*Logical Operation, LIKE , Between - Integer*/
    //		criteria.add(
    //				Restrictions.or(
    //						Restrictions.like("name", "%Hibernate%"),
    //						Restrictions.like("name", "%Spring%"))).
    //						add(Restrictions.between("price", new Integer(10), new Integer(60)));

    /*(String) MatchMode*/
    //		Criterion startRest = Restrictions.like("name", "Spring", MatchMode.START);
    //		Criterion anywhereRest = Restrictions.like("name", "Spring", MatchMode.ANYWHERE);
    //		criteria.add(anywhereRest);

    /*JOIN, ORDER */
    //		criteria.createAlias("stock","st").
    //		addOrder(Order.desc("name")).
    //		addOrder(Order.asc("publishedDate")).
    //		add(Restrictions.like("name","%Spring%")).
    //		add(Restrictions.ge("st.count", new Integer(5)));

    /*QBE - Query By Example : Not working now*/
    Book book = new Book();
    book.setId(1769472);
    Example exampleBook = Example.create(book);
    criteria.add(exampleBook);

    System.out.println("[Criteria] = " + criteria.toString());
    resultEntities = criteria.list();
    return resultEntities;
  }
 @Override
 public String toString() {
   return "DetachableCriteria(" + criteria.toString() + ')';
 }