-->
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 problems and native SQL query problem
PostPosted: Mon Apr 04, 2005 6:42 am 
Newbie

Joined: Wed Mar 23, 2005 1:24 am
Posts: 12
Hibernate version 3.0

Hi

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

i have something like this in my database

Vendor which has columns as : sellerid,sellername
Vendor1 which has columns as : sellerid,address

values in Vendor are as follows: 1001 Hibernate
values in Vendor1 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 Vendor as t1,Vendor1 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 Vendor t1,Vendor1 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 Vendor t1,Vendor1 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


hibernate generated query is
Hibernate: select vendor0_.sellerid as sellerid0_, vendor0_.sellername as sellername0_, vendor1_.sellerid as sellerid1_, vendor1_.sellername as sellername1_ from vendor vendor0_, vendor vendor1_ where (vendor0_.sellerid=vendor1_.sellerid )


The related Hbm files of vendor and vendor1 table are as follows:

Vendor.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.session.Vendor"
table="vendor"
>

<composite-id>
<key-property
name="sellerid"
column="sellerid"
type="java.lang.String"
length="100"
/>
<key-property
name="sellername"
column="sellername"
type="java.lang.String"
length="100"
/>
</composite-id>


<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->


</class>
</hibernate-mapping>



Vendor1.hbm.xml


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.session.Vendor1"
table="vendor1"
>

<composite-id>
<key-property
name="sellerid"
column="sellerid"
type="java.lang.String"
length="100"
/>
<key-property
name="address"
column="address"
type="java.lang.String"
length="100"
/>
</composite-id>


<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->


</class>
</hibernate-mapping>

_________________
Regards
Karthik


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 4:44 am 
Newbie

Joined: Fri Mar 18, 2005 7:58 am
Posts: 8
Hibernate 3 has something like this:

createSqlQuery(String query).addEntity(String alias,Class name)

Hope this helps!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 4:45 am 
Newbie

Joined: Fri Mar 18, 2005 7:58 am
Posts: 8
Hibernate 3 has something like this:

createSqlQuery(String query).addEntity(String alias,Class name)

Hope this helps!!


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.