搜档网
当前位置:搜档网 › setParameterList

setParameterList

突然发现Query.setParameterList原来是如此:
有两种参数的重载方式:
Java代码
/**
* Bind multiple values to a named query parameter. The Hibernate type of the parameter is
* first detected via the usage/position in the query and if not sufficient secondly
* guessed from the class of the first object in the collection. This is useful for binding a list of values
* to an expression such as foo.bar in (:value_list).
* @param name the name of the parameter
* @param vals a collection of values to list
*/
public Query setParameterList(String name, Collection vals) throws HibernateException;

/**
* Bind multiple values to a named query parameter. This is useful for binding
* a list of values to an expression such as foo.bar in (:value_list).
* @param name the name of the parameter
* @param vals a collection of values to list
* @param type the Hibernate type of the values
*/
public Query setParameterList(String name, Object[] vals, Type type) throws HibernateException;

/**
* Bind multiple values to a named query parameter. The Hibernate type of the parameter is
* first detected via the usage/position in the query and if not sufficient secondly
* guessed from the class of the first object in the collection. This is useful for binding a list of values
* to an expression such as foo.bar in (:value_list).
* @param name the name of the parameter
* @param vals a collection of values to list
*/
public Query setParameterList(String name, Collection vals) throws HibernateException;

/**
* Bind multiple values to a named query parameter. This is useful for binding
* a list of values to an expression such as foo.bar in (:value_list).
* @param name the name of the parameter
* @param vals a collection of values to list
* @param type the Hibernate type of the values
*/
public Query setParameterList(String name, Object[] vals, Type type) throws HibernateException;


它们都是用在hql/sql语句 in (...)情况下的, list或object[]会组成in集合, 并不是本以为的变成:
set(0, para1);
set(1, para2);
...

另外有一个方法,需要注意了:
Java代码
/**
* Bind values and types to positional parameters.
*/
public Query setParameters(Object[] values, Type[] types) throws HibernateException;

/**
* Bind values and types to positional parameters.
*/
public Query setParameters(Object[] values, Type[] types) throws HibernateException;

这里又不是用在in了,而是顺序组装参数:
Set(0, param1);
Set(1, param2);
...

相关主题