-->
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.  [ 3 posts ] 
Author Message
 Post subject: Join queries
PostPosted: Mon Apr 04, 2005 6:01 am 
Newbie

Joined: Wed Mar 23, 2005 1:24 am
Posts: 12
Hi

I have problem when i use join queries let me state with simple example

i have something like this in my database

Table1 which has columns as : id,name
Table2 which has columns as : id,address

values in Table1 are as follows: 1001 Hibernate
values in Table2 are as follows: 1001 Gavin King

k

normally when i need to query joins i will do this way in native SQL

select t1.name,t2.address from Table1 as t1,Table2 as t2 where t1.id=t2.id

i will get the rowset using jdbc code okay

now when i use HQL query

select t1.name,t2.address from Table1 t1,Table2 t2 where t1.id=t2.id

I do get an object but iam not able to type cast it reason being i do not have a bean which i can type cast it into it will come out as a javabean which i do not have right in this case

how can i get the values out of the object...

i tried an alternative solution too like this

select distinct new com.Join(t1.name,t2.address) from Table1 t1,Table2 t2 where t1.id = t2.id

Join is a java bean that takes name and address as paramter in its constructor usign this i get the values its useful surely ..

1.I need to know how can i do a join query apart from this technique without using distinct and wat will be the object that i will get when i apply a joined query.

2. How to use Native SQL queries ur api shows me three parameters where as Hibernate 3.0 has only one paramter to the method

api
createSQLQuery(String query,String alias,Class name)

but hibernate 3.0 jar has somehting like this
createSQLQuery(String query alone)'

Your documentation in pdf along with hibernate download also says it takes 3 parameters but your api shows me that method takes only one parameter that is native sql query alone

Am i doing something worng or something needs to be changed at api and at documentation


can anyone in hibernate team help me out with this problem

I would appreciate if anyone can explain me how a join query can be executed and the type of object that will come when i do a join query

Thanks
Karthik

_________________
Regards
Karthik


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 12:15 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
all this is well documented, what you get is Object[]

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Join query problem
PostPosted: Mon Apr 04, 2005 10:25 pm 
Newbie

Joined: Wed Mar 23, 2005 1:24 am
Posts: 12
Hi Anthony

Its well documented i know its a object array when i invoke something like this

List result = session.createQuery("select v1.sellername,v2.address from Vendor v1,Vendor v2 where v1.sellerid=v2.sellerid");

the result will contain object i know it but on which object should i be casting this to retrieve the values out of the object when i use reflection on the object i get try to access the methods in it it says the methods pertaining only to objects k

where as a normal query like this
"from Vendor"

using reflection if i look on to it ,it displays the getters and setters for that Vendor.hbm.xml which has been written in java code

is thr anyways i can use join queries and get values with having to cast on any object

PS:i can still use reflection on queries without join to get the values of the object without having to type cast it into their javabeans which we would have written for each .hbm.xml file

Can u explain me how a join query will get executed in this scenario how can i get the values out of it

_________________
Regards
Karthik


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