Solved

multiple joins in hibernate

Posted on 2007-03-29
8
2,113 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 24

Accepted Solution

by:
Tomas Helgi Johannsson earned 500 total points
Comment Utility
   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
Comment Utility
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 24

Expert Comment

by:Tomas Helgi Johannsson
Comment Utility
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
 
LVL 20

Author Comment

by:chaitu chaitu
Comment Utility
i didnt find anywhere HibernateUtil class;how dos it look like
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
Comment Utility
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 24

Expert Comment

by:Tomas Helgi Johannsson
Comment Utility
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
Comment Utility
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
Comment Utility
 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
where is session ID cache stored 1 38
wordcount challenge 11 73
Python Assistance 7 31
recursion example 16 68
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now