Helloo,
I've use Hibernate with Java 1.7 SE and HSQL library
I've onhe question how to create query in subquery.
Query Description
I have 40 000 records. When I perform Insert operation with
hibernate they add new record with new ID. Now, I must now
on which page is new record. E. g. I set filter and order so
new record won't be last on list.
In HSQL I can do this with:
SELECT ROWNUM(), ID FROM (SELECT * FROM MYTABLE) WHERE ID=100
It's give me result "5 100" - so ID 100 is 5 in result set.
How can create this query in Hibernate?
Source code for list record
Code:
Session session = null;
Transaction tx = null;
Object identity = null;
try {
identity = createSession();
session = currentSession();
tx = session.beginTransaction();
Example exampleExpr = null;
if (example != null) {
exampleExpr = Example.create(example)
.ignoreCase()
.excludeZeroes()
.enableLike();
}
Criteria q = session.createCriteria(Zmarli.class )
.add(Restrictions.ne("deleted", true ));
if (exampleExpr != null)
q.add(exampleExpr);
if (sortByColumnName != null) {
q.addOrder(sortOrder == javax.swing.SortOrder.ASCENDING ? Order.asc(sortByColumnName):Order.desc
(sortByColumnName));
}
List<Zmarli> listr = q.list();
tx.commit();
tx = null;
It is possible to create Criteria with ROWNUM() function on result set listr or there is any other solution?
Thanks for answer,
kr3niu