File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Difference Between Unidirectional and Bidirectional Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Difference Between Unidirectional and Bidirectional" Watch "Difference Between Unidirectional and Bidirectional" New topic
Author

Difference Between Unidirectional and Bidirectional

i ananthaprakash
Greenhorn

Joined: Aug 31, 2011
Posts: 9
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.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
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.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
i ananthaprakash
Greenhorn

Joined: Aug 31, 2011
Posts: 9
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

Joined: Aug 31, 2011
Posts: 9
Can anybody clarify me the above query as it is little urgent.
Thank You in advance.......
sagarpol tambepol
Greenhorn

Joined: Mar 02, 2013
Posts: 1
Please Can you more elaborate on Nagivation from from one to another class?
Jayasiva kammana
Greenhorn

Joined: Mar 03, 2013
Posts: 1
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.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference Between Unidirectional and Bidirectional
 
Similar Threads
Hibernate !!!! mapping help
org.hibernate.HibernateException: identifier of an instance of Address was altered from 2 to 3
Unidirectional & Bi directional
doubt in domain relationship
EJB3 Entity Relationship