No LIMIT clause in HQL (Hibernate 3)

在Hibernate 2中习惯了将limit ?, ?语句写在HQL中,使用Hibernate 3时突然发现limit语句不起作用了,hibernate生成的SQL中完全不见limit的踪影,它被忽略了!

limit在分页中可是至关重要的工具。当然某些牛人把整个表都取出来在内存中作分页,我却没有这种魄力。

HQL的文档中也没有提到LIMIT,可能真的是不支持了。不过我们可以用Criteria这个接口的setFirstResultsetMaxResults来实现limit。Query接口也有类似的方法。

如果用的是Spring的HibernateTemplate,则可以调用其findByCriteria方法来实现相同的功能。

This entry was posted on Friday, July 4th, 2008 at 3:05 pm and is filed under Database. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Comment »

Comment by kenwell
2008-07-08 22:09:24

java大牛好

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)

Please copy the string ZApjES to the field below: