-->
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.  [ 5 posts ] 
Author Message
 Post subject: Column not found exception..!
PostPosted: Mon Jul 16, 2007 3:34 am 
Newbie

Joined: Mon Jul 16, 2007 2:56 am
Posts: 3
Hi,

Iam trying to join two tables and retrieve some fields using sql.

i have used session.createSqlQuery("query");

Strangely in the select clause of the query if i use * ,the above code dosent throw any error and is working fine..but if i specify only one or two fields in the select clause it throws a column not found error

like for example select * from Cats cats,Dogs dogs where cats.catid = dogs.dogId is working fine

but if i use select cats.catsid,dogs.dogId from Cats cats,Dogs dogs where cats.catid = dogs.dogId is throwing a exception

can any one help me out in this..?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 7:55 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi


In createSQLQuery you have to select all properties of a given class. You have two options

1. write your query as follws

select cats.Catsid as {cats.catsid}, dogs.DogId as {dogs.dogId }, null as {cats.otherprop1} from Cats cats,Dogs dogs where cats.catid = dogs.dogId


2.(recomanded)

List list=sess.createCriteria(Cat.class,"c")
.createCriteria("Dog","d")
.setProjection(Projections.projectionList() .add(Projections.property("d.dogId")) .add(Projections.property("c.catsid")
)
).list();


Top
 Profile  
 
 Post subject: Column not found exception..!
PostPosted: Mon Jul 16, 2007 8:10 am 
Newbie

Joined: Mon Jul 16, 2007 2:56 am
Posts: 3
Thanks for the reply amily..!

But won't it be a performance hit
since in both the cases the entire fields in the table has to be fetched and it boils out to be the same as select * from table..?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 8:16 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

No You are wrong
in case 2 only select d.dogId and c.catsid
thats why i recomand it

Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 12:28 am 
Newbie

Joined: Mon Jul 16, 2007 2:56 am
Posts: 3
amila733 wrote:
Hi

No You are wrong
in case 2 only select d.dogId and c.catsid
thats why i recomand it

Amila

(Don't forget to rate if helps)
Quote:
Quote:


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