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.  [ 2 posts ] 
Author Message
 Post subject: sql-query join
PostPosted: Thu Aug 28, 2008 4:36 am 
Beginner
Beginner

Joined: Fri Apr 27, 2007 11:50 am
Posts: 23
Hi Guys,

I'm trying to write a dynamic sql-query which contains a join which needs to be used within the where clause, but doesn't need to be returned, but i seem to be having problems.

The sql being denerated is currently looking like this:

Code:
SELECT {h.*}  FROM Hotel {h}, Room {r} WHERE 1=1 AND {r.Capacity} BETWEEN 10 AND 100 ORDER BY {h.Holindex} ASC


With a generate sql statement as follows:

Code:
IQuery query = NHibernateSession.CreateSQLQuery(sql.ToString())
                .AddEntity("h", typeof(Hotel))
                .AddJoin("r", "h.Rooms");


But no matter what i try, i keep getting erros like

Quote:
No column name found for property [Capacity] for alias [r]


Does anybody have any ideas?


Top
 Profile  
 
 Post subject: Typical....
PostPosted: Thu Aug 28, 2008 4:50 am 
Beginner
Beginner

Joined: Fri Apr 27, 2007 11:50 am
Posts: 23
...as soon as you post it on the forum you find the answer.

It looks like i don't really need the AddJoin and i just needed to make my sql join as follows:

Code:
SELECT {h.*}  FROM Hotel h LEFT JOIN Room r ON r.HotelId = h.HotelId WHERE 1=1  AND r.Capacity BETWEEN 10 AND 100 ORDER BY {h.Holindex} ASC


I think the entity mappings was confusing me. Looks simple now i have the solution :)

Thanks anyway guys. Feel free to delete this topic, or keep it for anyone else who has the same problem.

Thanks

Matt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.