Newsletter

Hibernate Left Join, Hibernate Left Join Example

Hibernate » on Aug 10, 2011 { 9 Comments } By Sivateja

Left join means, the objects from both sides of the join are selected and more objects  from left side are selected, even though no equal objects are there at right side, no confusion you will be able to understand if you go through this example i guess :-)

Let us see an example on hibernate left join, am taking one-to-many to explain this concept files required….

  • Vendor.java
  • Customer.java
  • Vendor.hbm.xml
  • Customer.hbm.xml
  • hibernate.cfg.xml
  • urLogic.java

Vendor.java

Customer.java

Vendor.xml

———

Customer.java

hibernate.cfg.xml

urLoic.java

 

Explanation:

  • Actually in urLogic.java see line number 27, i have written select v.vendorName, c.customerName from Vendor v Left Join v.children c
  • See before Left Join key word, i selected from Vendor v, after Left Join keywork v.children c
  • Means, actually we know in one to many if we select the data from parent then, we will get the data automatically from the children table, i mean records mapping with the parent table, hope you remembered :-)
  • Let in parent we have 5 records, and in children we have 3 records.  And 2 records are having relation with children table records

Before execute this program…..

Out put once we executed……

 

And thats it mates.., try with Right Join and remaining joins just same concept.

You Might Also Like

  ::. About the Author .::

Java4s_Author
- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

9 Responses to “Hibernate Left Join, Hibernate Left Join Example”
  1. Rawoof says:

    you wrote Customer.java insted of customer.xml

  2. Titin says:

    What is the use of CallBack interface in hibernate?

    • Salman Khan says:

      The use of callback method in hibernate is basically for increase the performance.
      Suppose, If we are not using callback method and if we call a method in another method then in this case first we have to execute first method and then execute calling method. or we can say that in calling method whatever method we are calling of that method code will be come.
      And If We are using callback method then first code will be executed in the method then we have to call only response of that method. Becoz of this definitely performance will be improved.

  3. Gokulnathan says:

    It is private Set Childern instead private Set Customer. Respectively the setter & getter methods. Change it!

  4. mateen says:

    db schema is missing

  5. Mukesh says:

    what is this (Join v.children c) in query

  6. Bhujatha Reddy says:

    How to make relationship between three tables using hibernate,
    Ex, i have one Account tale with fields accno,name, balance
    and usertable with fields user_id, account_id, and third table is movie_ticket with fields ticket_I’d, ticket_price,ticket_count

    Can you please help me how to deduct balance and ticket count when i book tucket

    Thank u

  7. Navya says:

    left join in that vendor.xml is there but that is vendor.hbm.xml file
    and customer.java but customer.hbm.xml right

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Hibernate Spring Struts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.