Get all updates of Java4s
Follow Us: Email Newsletter

Hibernate Left Join, Hibernate Left Join Example

Hibernate » On Aug 10, 2011 { 7 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 Author ♦

Java4s_Author
sivateja@java4s.com
Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

7 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?

  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.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
Upcoming
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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