Previous Page
Hibernate FAQs
Next Page


19.Define cascade and inverse option in one-many mapping?
cascade - enable operations to cascade to child entities.
cascade="all|none|save-update|delete|all-delete-orphan"

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?

20.What does it mean to be inverse?
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.

21.What do you mean by Named – SQL query?
Named SQL queries are defined in the mapping xml document and called wherever required.
Example:

<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 {emp.name}
      FROM Employee EMP WHERE emp.NAME LIKE :name
</sql-query>



Invoke Named Query :

List people = session.getNamedQuery("empdetails")
                   .setString("TomBrady", name)
                   .setMaxResults(50)
                   .list();


22.How do you invoke Stored Procedures?

<sql-query name="selectAllEmployees_SP" callable="true">
 <return alias="emp" class="employee">
   <return-property name="empid" column="EMP_ID"/>       

   <return-property name="name" column="EMP_NAME"/>       
   <return-property name="address" column="EMP_ADDRESS"/>
    { ? = call selectAllEmployees() }
 </return>
</sql-query>
Ex:
my mapping file is 
<sql-query name="book_testing" callable="true">
<return alias="book" class="Book">
<return-property name="lngBookId" column="id" />
<return-property name="strBookName" column="bookname" />
</return>
{ call book_return( ?,:lngBookId) }
</sql-query>

my program is

List ls = session.getNamedQuery("book_testing")
.setInteger("lngBookId",4)
.list();


23.Explain Criteria API
Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.
Example :

List employees = session.createCriteria(Employee.class)
                       .add(Restrictions.like("name", "a%") )
                           .add(Restrictions.like("address", "Boston"))
                        .addOrder(Order.asc("name") )
                        .list();


24.Define HibernateTemplate?
org.springframework.orm.hibernate.HibernateTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.

 


Previous Page
Next Page