首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

HibernateTemlate的find方法中的参数,该如何处理

2012-05-21 
HibernateTemlate的find方法中的参数public ListApplication findByEmp(Employee emp){return (ListUse

HibernateTemlate的find方法中的参数
public List<Application> findByEmp(Employee emp)
{
  return (List<User>)getHibernateTemplate().find("from Application as a where" +
  "a.attend.employee=?", emp);
}

请问 find方法中 ? 这个 占位符 后面 那个 emp 参数 是什么意思,
还有 find方法中的 HQL 语句必须要写成 带 + 连接符 这样的 格式 吗 可不可以不写 加号 呢?

[解决办法]
那个emp就代表你要查询的条件啊。你先前那个占位符不就是为他占得地方么。
hibernate API是这样写的。
public List find(String query,
Object value,
Type type)
throws HibernateException Deprecated. use Session.createQuery(java.lang.String).setXYZ.Query.list() 

Execute a query with bind parameters, binding a value to a "?" parameter in the query string.
 
Parameters:query - the query stringvalue - a value to be bound to a "?" placeholder (JDBC IN parameter).type - the Hibernate type of the value Returns:a distinct list of instances (or arrays of instances) Throws: HibernateExceptionSee Also:for access to Type instances


[解决办法]
不需要+号 你那个+好是你按了回车。 eclipse自动给你拼接上去的。

热点排行