Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Hibernate Interview Questions and Answers

Ques 26. What is the difference between and merge and update?

Ans. Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session.

Is it helpful? Add Comment View Comments
Ques 27. How do you define sequence generated primary key in hibernate?
Ans. Using <generator> tag.
<id column=\"USER_ID\" name=\"id\" type=\"java.lang.Long\">
<generator class=\"sequence\">
<param name=\"table\">SEQUENCE_NAME</param>
Is it helpful? Add Comment View Comments
Ques 28. Define cascade and inverse option in one-many mapping?
Ans. cascade enable operations to cascade to child entities.
inverse mark this collection as the "inverse" end of a bidirectional association. inverse="true|false" Essentially "inverse" indicates which end of a relationship should be ignored, so when persisting a parent who has a collection of children, should you ask the parent for its list of children, or ask the children who the parents are?
Is it helpful? Add Comment View Comments
Ques 29. What does it mean to be inverse?
Ans. It informs hibernate to ignore that end of the relationship. If the one-to-many was marked as inverse, hibernate would create a child->parent relationship (child.getParent). If the one-to-many was marked as non-inverse then a child->parent relationship would be created.

In Hibernate, only the “relationship owner” should maintain the relationship, and the “inverse” keyword is created to defines which side is the owner to maintain the relationship. However the “inverse” keyword itself is not verbose enough, I would suggest change the keyword to “relationship_owner“.

In short, inverse=”true” means this is the relationship owner, and inverse=”false” (default) means it’s not.

Suppose Stock is parent and StockDailyRecords is Child object.

Inverse keyword is applied in one to many relationship. Here’s the question, if save or update operation perform in “Stock” object, should it update the “stockDailyRecords” relationship?

1. inverse=”true”
If inverse=”true” in the set variable, it means “stock_daily_record” is the relationship owner, so Stock will NOT UPDATE the relationship.

2. inverse=”false”
If inverse=”false” (default) in the set variable, it means “stock” is the relationship owner, and Stock will UPDATE the relationship.

If keyword “inverse” is not define, the inverse = “false” will be used, which is
Is it helpful? Add Comment View Comments
Ques 30. What do you mean by Named - SQL query?
Ans. Named SQL queries are defined in the mapping xml document and called wherever required.
<sql-query name = \"empdetails\">
<return alias=\"emp\" class=\"com.test.Employee\"/>
SELECT emp.EMP_ID AS {emp.empid}, emp.EMP_ADDRESS AS {emp.address}, emp.EMP_NAME AS {} FROM Employee EMP WHERE emp.NAME LIKE :name

Invoke Named Query :
List people = session.getNamedQuery(\"empdetails\") .setString(\"TomBrady\", name) .setMaxResults(50) .list();
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2018 WithoutBook