Link to home
Start Free TrialLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

multiple joins in hibernate

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
ASKER CERTIFIED SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chaitu chaitu

ASKER

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?
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
i didnt find anywhere HibernateUtil class;how dos it look like
The Hibernate Util class is also in the zip file in the Join example.

Regards,
  Tomas Helgi
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>
 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;