Thanks for your attention, and sorry for mi English :S
I'm using JPA 2.0 with Hibernate 4.X to do some sql native queries. Te code is very simple:
Code:
private void doIt() throws Exception {
EntityManager em = getEntityManager();
Query q = em.createNativeQuery("A very simple native query, which return no entities, but collections of arrays");
q.setFirstResult(0);
q.setMaxResults(5);
Collection<Object> results = q.getResultList();
System.out.println("1"); //Means page 1
for (Object elem : results) {
String line = "";
Object[] row = (Object[]) elem;
for (Object object : row) {
if(object==null){
object="null";
}
line += object +"("+object.getClass()+")"+ ",";
}
System.out.println(row.length + " " + line);
}
em = getEntityManager();
q = em.createNativeQuery("The same simple native query, which return no entities, but collections of arrays");
q.setFirstResult(5);
q.setMaxResults(5);
results = q.getResultList();
System.out.println("2"); //Means page 2
for (Object elem : results) {
String line = "";
Object[] row = (Object[]) elem;
for (Object object : row) {
if(object==null){
object="null";
}
line += object +"("+object.getClass()+")"+ ",";
}
System.out.println(row.length + " " + line);
}
em = getEntityManager();
q = em.createNativeQuery("The same simple native query, which return no entities, but collections of arrays");
q.setFirstResult(10);
q.setMaxResults(5);
results = q.getResultList();
System.out.println("3"); //Means page 3
for (Object elem : results) {
String line = "";
Object[] row = (Object[]) elem;
for (Object object : row) {
if(object==null){
object="null";
}
line += object +"("+object.getClass()+")"+ ",";
}
System.out.println(row.length + " " + line);
}
}
And my result is this:
Code:
1
data1,data2,...,data-n -->I need this output
data1,data2,...,data-n
data1,data2,...,data-n
data1,data2,...,data-n
data1,data2,...,data-n
2
data1,data2,...,data-n,6 -->OMG! lol
data1,data2,...,data-n,7
data1,data2,...,data-n,8
data1,data2,...,data-n,9
data1,data2,...,data-n,10
3
data1,data2,...,data-n,11
data1,data2,...,data-n,12
data1,data2,...,data-n,13
data1,data2,...,data-n,14
data1,data2,...,data-n,15
In short, the output in the first page has n items per row (that's my desired output), but the second and third pages have n+1 items, and the additional item seems to be the number of the row that has been brought.
Someone has the same thing happened? I have searched in the Hibernate's documentation, but I could not solve this "funny :@" problem.
This code was executed with Toplink, and It doesn' have the problem.
Thank you very much!! :)