chaitu chaitu
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Then you write your select according to what columns you want
example
HibernateUtil.checkData("s elect name from Supplier");
HibernateUtil.checkData("s elect name,description from Product");
Regards,
Tomas Helgi
example
HibernateUtil.checkData("s
HibernateUtil.checkData("s
Regards,
Tomas Helgi
ASKER
i didnt find anywhere HibernateUtil class;how dos it look like
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
And other Hibernate examples :
http://www.java2s.com/Code/Java/Hibernate/CatalogHibernate.htm
Regards,
Tomas Helgi
The Hibernate Util class is also in the zip file in the Join example.
Regards,
Tomas Helgi
Regards,
Tomas Helgi
ASKER
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>
<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>
ASKER
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_.s upplierId
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("s elect name from Supplier");
this method again execute the query;i don't want that;
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_.s
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("s
this method again execute the query;i don't want that;
ASKER
i want only certain columns from both of these tables;then how will you do?