Hibernate Interview Questions – Part 3

Hibernate Interview Questions – Part 3

Hibernate Interview Questions – Part 1Part 2

Explain One – to – One Mapping:
Example:
Consider we have 2 tables, Employee and Employee Address. We save the employee details at one table like his name, employee number etc and we save employee address in another table. We will have a one to one relationship for specific employee from employee table to specific records in Employee Address table.

Consider there is an employee named Alpha in Employee table and let the primary key for Alpha be 1. Now the table Employee will have an column that links to Employee Address table and that Employee Address will point to a record in Employee Address table.

Detailed Explanation Here


Explain OneToMany Mapping:
Example:
Consider an employee might have more than one address, So as OnetoMany mapping points out, A single employee can have more than one address in another table. (Detail Here)


Explain ManytoMany Mapping:
let us consider 2 entities – Employee and Address. An employee can have more than one address let us assume permanent and temporary address, Same way more than one employee would have stayed in the temporary address. This scenario shows Employee can have more than one address and an address can have more than one employee. This is ManyToMany mapping. (Details Here)


Explain Table per Concrete Class:
In this method, a table is created for each class in the inheritance. Each table will have its own property columns and also has its base class properties. We will have repeated columns of base class in all sub classes


Explain Table per Class:
In this method, a single table is created for all classes both Base and Subclass. We have to define a column Discriminator column to differentiate object of base and subclass.(Detailed Explanation Here)


Explain Table per Subclass:
This method, creates a table for each subclass. The difference between table per concrete class and Table per subclass is the Inherited tables will not create columns of base class. It uses foreign key and points to base class for base class properties(Detailed Explanation Here)


 

Read More