Solved

multiple joins in hibernate

Posted on 2007-03-29
8
2,135 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to parse custom JSON to POJO java 4 73
Error trying to install RTMT Win7 5 60
java stored proc example 9 31
use lov values 2 50
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

777 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