Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Difference Between Unidirectional and Bidirectional

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am really confused in understanding difference between Unidirectional and Bidirectional mapping in Hibernate 3.5.
Can some body explain me with an example with tables and also the usage when to use what.

I have setup the hibernate and i have already did some egs i have mapped some <one-to-one> mapping and all.
But Concept wise i am not able to understand.
Thanks in advance.
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unidirectional - means only allow navigating from one side of the mapping to another. For example in the case of a one-many mapping, only allow navigation from the one side to the many side. Bi-directional means to allow navigation both ways.
 
i ananthaprakash
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok Thanks Bosun..

Now let us consider an example..

Employee -- Class
empno
emp_name
dept_id

Dept---Class
dept_id
dept_name
dept_location

so 1-to-Many relationship occurred in the above case.
Now i am stuck up in understanding the concept.
When is this mapping considered and go the following questions
1) Is this mapping considered only while fetching the data from database?
2) Is this mapping considered only while storing data to database?
3) Or this is considered for both 1) and 2)
4) Why mapping is used?
5) How to decide which mapping to be used for eg lets consider One-to-Many relationship {Unidirectional or Bidirectional}?

Can you explain a little more with the above example.

Thanks a ton
 
i ananthaprakash
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody clarify me the above query as it is little urgent.
Thank You in advance.......
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Can you more elaborate on Nagivation from from one to another class?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear AnathaPrakash,

As Per Bosun Bello Suggestion the basic understanding of Unidirectional and bidectional is correct. have glance on with sample examples

Let us Consider Class Employee with name ,age and phone as properties.
Unidirection
public class Employee{
private String name;
private int age;
private String phone;
private Department dept;
//getters and setters
}

we have Department Class with deptId,deptName,deptLocation as properties of the Department Class.

public class Department{
private String deptId;
private String deptName;
private deptLocation;
//getters and setters
}

In the above Java class configuration defined department object as property of the employee class then we can conclude that there is mapping exist between Employee and department.i.e., Employee is associated department .then above scenario Every employee is mapped to department ,department doesn't know about Employee,because of department doesn't have any association with Employee(i.e.,Department has no Employee). then it unidirection.

Bidirection:

Consider Class Person

Class Person{
private String fName;
private String lName;
private int age;
private Address address;
//getters and setters;

}


Class Address{
private String doorNo;
private String street;
priavate String city;
private String country;

private Person person;

}


In the above Person class have address and Address can have Person and then we will conclude that that every person has address and each address is mapped to employee so it is birection.


 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic