P E N C I L
Login
Hibernate Query
  1. Ref
    1. https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.htm
  2. Note:
    1. HibernateTemplate is deprecated from spring 4
  3. To create session
    1. SessionFactory.getCurrentSession()
  4. Query with HQL 
    1. getSession().createQuery("FROM Employee E WHERE E.id=:myvar and E.x=?).
      query.setParameter("myvar", 10);
      query.setLong(0, 1234L)
    2. query.list();
      query.executeUpdate()
    3. HQL
      1. getSession().createQuery("FROM Employee E WHERE E.id=:myvar and E.x=?).
      2. getSession().createQuery("delete from "+class.getName()).
  5. Query with Hibernate Criteria API
    1. Criterion.list()
    2. criterion = Session.createCritiria(E.class).add(Restrictions.eq("myPk.username", "username"));
    3. session.createCriteria(Connected.class, "c").add(eq("c.userid", username)).setProjection(Projections.property("c.client")).uniqueResult();
    4. Restrictions.like()