-->
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: Nested Query, please help
PostPosted: Mon Jul 13, 2009 7:12 am 
Newbie

Joined: Sun Aug 24, 2008 3:21 pm
Posts: 8
Hi.

I need a nested query to lock some rows (oracle-db).
Native sql looks like this:
Code:
select * from (
    select * from person p where p.name = :name order by p.name
) where rownum < 10 for update p.id


My experience with hibernate:

First try:
Code:
List personen = session.createQuery("from PERSON as p where p.name = ? order by p.name")
     .setString(0, argName )
     .setMaxResults(10)
     .setLockMode("p", LockMode.UPGRADE)
     .list();

The generated sql was wrong (a known hibernate bug:-( in my version). Hibernate mixes the aliases. Without alias, i can not set a LockMode()..

Second try:
I try to use a detached Subquery. But this generate sql looks like this:
Code:
SELECT * FROM person p
  WHERE p.id = (SELECT p2.id FROM person as p2 WHERE .. ORDER BY p2.name)
     AND rownum < 10

The order by Statement is not allowed inside a nested Query and i get an error (ORA-00907: missing right parenthesis).

Our person class has any subclasses with different discriminator values. Therefore i won't use a native sql with hard coded discriminator values inside.
Does anybody know a suggestion without native sql?

best regards


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.