Solved

multiple joins in hibernate

Posted on 2007-03-29
8
2,150 Views
Last Modified: 2013-11-24
TABLE1
TABLE2
TABLE3

* from TABLE1 T1,TABLE2 T2,TABLE3 T3
where T1.portid=T2.id and T2.tshid=T3.id

I want information both from T1 and T3 tables.how to do this kind of multiple joins in hibernate.how the java classes and mapping files look like
0
Comment
Question by:chaitu chaitu
  • 4
  • 4
8 Comments
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 500 total points
ID: 18822122
   Hi!

Here is an Hibernate Join example with 2 tables: http://www.java2s.com/Code/Java/Hibernate/HQLFetchAssociationsHQLInnerJoin.htm

Applying the third table should be straightforward.

Regards,
  Tomas Helgi
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 18822217
I dont want all columns from supplier and product tables;

i want only certain columns from both of these tables;then how will you do?
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 18822268
Then you write your select according to what columns you want
example
HibernateUtil.checkData("select name from Supplier");
HibernateUtil.checkData("select name,description from Product");

Regards,
   Tomas Helgi
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 20

Author Comment

by:chaitu chaitu
ID: 18822301
i didnt find anywhere HibernateUtil class;how dos it look like
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 18822354
Here is the Hibernate Util class : http://www.java2s.com/Code/Java/Hibernate/HibernateUtility.htm

And other Hibernate examples :
http://www.java2s.com/Code/Java/Hibernate/CatalogHibernate.htm

Regards,
  Tomas Helgi
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 18822363
The Hibernate Util class is also in the zip file in the Join example.

Regards,
  Tomas Helgi
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 18822728
do i need to mention many-one tag in products.hbm.xml ??

<hibernate-mapping>
   <class name="com.Products">
      <id name="id" type="java.lang.Long">
         <generator class="increment"/>
      </id>

      <property name="name" type="string"/>
       <property name="description" type="string"/>
        <property name="price" type="double"/>
   

   </class>
</hibernate-mapping>
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 18822964
 String hql = "from Supplier s inner join fetch s.products as p";
              Query query = session.createQuery(hql);

it will execute below query;

select supplier0_.id as id1_0_, products1_.id as id0_1_, supplier0_.name as name1_0_, products1_.name as name0_1_, products1_.description as descript3_0_1_, products1_.price as price0_1_, products1_.supplierId as supplierId0__, products1_.id as id0__ from Supplier supplier0_ inner join Products products1_ on supplier0_.id=products1_.supplierId

if i have 50 columns in Supplier and 100 columns in Products table then all those columns will come in this query;i want only specific columns in the query say 10 columns from both of these tables supplier and products then how will u reqrite this query?

HibernateUtil.checkData("select name from Supplier");

this method again execute the query;i don't want that;
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question