Solved

multiple joins in hibernate

Posted on 2007-03-29
8
2,123 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
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 18822301
i didnt find anywhere HibernateUtil class;how dos it look like
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 120
groupSum6 challenge 6 76
groovy example issue 10 87
Spring Framework HTTPSession management 1 21
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

948 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

21 Experts available now in Live!

Get 1:1 Help Now