-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ROWNUM() on result set
PostPosted: Mon May 20, 2013 3:31 am 
Newbie

Joined: Mon May 20, 2013 3:18 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.