Java Code Examples for org.hibernate.Query.setProperties()

The following are Jave code examples for showing how to use setProperties() of the org.hibernate.Query class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: training-sample   File: HibernateUserDao.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
public List<User> findByExample(User user) {
	List<User> users = null;
	Session session = sessionFactory.getCurrentSession();
	try {
		session.beginTransaction();
		Query query = session.createQuery("from User where name=:name and age=:age");
		query.setProperties(user);
		query.setProperties(user);
		users = (List<User>) query.list();
		session.getTransaction().commit();
	} catch (RuntimeException e) {
		session.getTransaction().rollback();
	}
	return users;
}
 
Example 2
Project: lemon   File: HibernateGenericDao.java   View Source Code Vote up 5 votes
/**
 * create query by hql and map.
 * 
 * @param hql
 *            String
 * @param map
 *            Map
 * @return Query
 */
public Query createQuery(String hql, Map<String, Object> map) {
    Assert.hasText(hql, "hql cannot be null");

    Query query = this.getSession().createQuery(hql);

    if (map != null) {
        query.setProperties(map);
    }

    return query;
}
 
Example 3
Project: training-sample   File: HibernateUserDao.java   View Source Code Vote up 5 votes
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
@Override
public List<User> findByExample(User user) {
	Query query = sessionFactory.getCurrentSession().createQuery("from User where name=:name and age=:age");
	query.setProperties(user);
	query.setProperties(user);
	return query.list();
}
 
Example 4
Project: DWSurvey   File: SimpleHibernateDao.java   View Source Code Vote up 5 votes
@Override
public Query createQuery(final String queryString, final Map<String, ?> values) {
	AssertUtils.hasText(queryString, "queryString不能为空");
	Query query = getSession().createQuery(queryString);
	if (values != null) {
		query.setProperties(values);
	}
	return query;
}