为啥Hibernate的HQL查询要使用别名呢?

今天写了一句超级简单的HQL语句,竟然报错

String hql = "from Book  where Book.ISBN=?";
Query query = session.createQuery(hql);
query.setString(0, "7-02-002475-0");
List<Book> list = query.list();
for(Book l : list) {
	System.out.println(l);
}

 

就一个Book实体类,错误信息如下

org.hibernate.QueryException: Unable to resolve path [Book.ISBN], unexpected token
	 [Book] [from cn.sobook.model.Book  where Book.ISBN=?]
	at org.hibernate.hql.ast.tree.IdentNode.resolveAsNakedComponentPropertyRefLHS(IdentNode.java:219)
	=

 混乱中采用别名,很和谐。

String hql = "from Book a where a.ISBN=?";

 

你可能感兴趣的:(Hibernate)