-->
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.  [ 6 posts ] 
Author Message
 Post subject: Subselect query
PostPosted: Mon Jan 09, 2006 8:04 am 
Newbie

Joined: Mon Jan 09, 2006 7:15 am
Posts: 3
I' m trying to translate to Hibernate this Query:
SELECT n.*, (select nl.sid from newsReaded nl where nl.newsfk=n.sid and nl.reader='john') as readed
FROM news n


I use a subquery in the select clause, then i have read "Hibernate in action" to look for subselects.

I read that HQL supports subqueries only in the where clause, but also i read that we can use Formulas in the property clause to put it. It would look like this:
<property
name="readed"
formula="( select clause )"
type="long"/>

But my problem is that i need to pass an external parameter. Instead of: nl.reader='john' i need to put something like nl.reader=v_name

I´m using hibernate version 3.0.
Thanks in advance for your valuable time.
Sorry for my English.
[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 8:09 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
you can access the columns available in your mapped class.

so writing
... nl.reader = name
will refer to column name of your reader.
Have a look at the examples in the reference. This is explained there!

Please rate if this helped.
Regards
Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 8:43 am 
Newbie

Joined: Mon Jan 09, 2006 7:15 am
Posts: 3
thanks for your reply... very thanks,
but the problem is not to access to any column name... the problem is that:
I use in the query an external parameter that i retrieved in the user session.
Thanks again for your valuable time.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 9:42 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
SELECT n.*, nl.sid
FROM news n LEFT JOIN newsReaded nl ON nl.newsfk=n.sid and nl.reader='john'


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 10:05 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I think this will not work with a mapping but with a query.

You could create a query using a subselect by yourself, so you will receive a tuple of objects.
obj[0] your object, obj[1] your additional value

Look for
Scalar results
and
subqueries
in the reference.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 10:57 am 
Newbie

Joined: Mon Jan 09, 2006 7:15 am
Posts: 3
baliukas, thanks for your query. I've tested queries with outer joins (like as yours and others) but i retrieve an erroneus results :(
and thanks also LaLiLuna.
I will use several queries instead of the unique query :S
I've tested that and the performance is not bad.


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

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.