This also works pretty well using Hibernate:

Criteria c = session.createCriteria(...);
c.setFirstResult(start);
c.setMaxResults(length);

But beware with using this. Hibernate has Java-Filters for some cases.
ResultTransformers can't be used in combination with paging. The query
will select the amount you need but the transformers could remove
results from that list.

We've noticed that if you automaticly join tables using the HBM file
(fetch) then Hibernate will remove results too. This is very annoying.

For example:
Table 1:
key - t2key - value
1 1 First entry
2 1 Second entry
3 2 Blabla
4 3 More bla..

Table 2:
key - value
1 Some value
2 Some other value
3 Some third value

If you fetch-join table 1 when you query table 2 and try to collect
the first 3 results hibernate will generate the following SQL:

select * from table2  t2 left join table1 t1 on t2.t2key = t2.key limit 0,2;

What will be retrieved:
1 Some value 1 1 First entry
1 Some value 2 1 Second entry
2 Some other value 3 2 Blabla

Because the first (queried) table has duplicate entries Hibernate will
create the following objects:

table1 object: "1, Some value"
with List<table2 object> {"1,1,First entry", "2,1,Second entry"}

and

table1 object: "2, Some other value"
with List<table2 object> {"3,2,Bla bla"}

Just two results... paging messed up :(

This is my experience with paging and ORM mappers, you have to be very
carefull hehe. If somebody here knows a solution to this problem,
please let me know!

Roy


On 12/3/07, Uwe Schäfer <[EMAIL PROTECTED]> wrote:
> wicketshafi schrieb:
>
> > how do I query the start and count in mysql....
>
>  The LIMIT clause can be used to constrain the number of rows returned
> by the SELECT  statement. LIMIT takes one or two numeric arguments,
> which must both be non-negative integer constants (except when using
> prepared statements).
>
> With two arguments, the first argument specifies the offset of the first
> row to return, and the second specifies the maximum number of rows to
> return. The offset of the initial row is 0 (not 1):
>
> SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15
>
> see http://dev.mysql.com/doc/refman/5.0/en/select.html
>
> --
>
> THOMAS DAILY GmbH
> Adlerstraße 19
> 79098 Freiburg
> Deutschland
> T  + 49 761 3 85 59 0
> F  + 49 761 3 85 59 550
> E  [EMAIL PROTECTED]
> www.thomas-daily.de
>
> Geschäftsführer/Managing Directors:
> Wendy Thomas, Susanne Larbig
> Handelsregister Freiburg i.Br., HRB 3947
>
> Registrieren Sie sich unter http://morningnews.thomas-daily.de für die
> kostenfreien TD Morning News, eine Auswahl aktueller Themen des Tages
> morgens um 9:00 in Ihrer Mailbox.
>
> Hinweis: Der Redaktionsschluss für unsere TD Morning News ist täglich um
> 8:30 Uhr. Es werden vorrangig Informationen berücksichtigt, die nach
> 16:00 Uhr des Vortages eingegangen sind. Die Email-Adresse unserer
> Redaktion lautet [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to