顯示具有 Hibernate 標籤的文章。 顯示所有文章
顯示具有 Hibernate 標籤的文章。 顯示所有文章

2010年5月20日 星期四

Hibernate Pagination

http://blog.hibernate.org/Bloggers/Everyone/Year/2004/Month/08/Day/14#pagination

public class Page {

private List results;
private int pageSize;
private int page;

public Page(Query query, int page, int pageSize) {

this.page = page;
this.pageSize = pageSize;
results = query.setFirstResult(page * pageSize).setMaxResults(pageSize + 1).list();

}

public boolean isNextPage() {
return results.size() > pageSize;
}

public boolean isPreviousPage() {
return page > 0;
}

public List getList() {
return isNextPage() ? results.subList(0, pageSize - 1) : results;
}

}

2009年9月29日 星期二

Hibernate Problem or Exception

Hibernate Problem or Exception

org.hibernate.hql.ast.QuerySyntaxException:
要先check 一次你的"HQL" example "from User" << 當中的User 並不是db table 的名稱, 而是object 的名稱 i.e. model.User (請跟足大細階)。

因為HQL 會以java 的object 來根據hbm.xml 內的對照表,找出db 內的table 以至column。