Search

Complete reference to Hibernate interview questions basic to advanced level : SE to Team Lead level Part - 4

Latest Answer: Add the hibernate related jar files into lib directory of any web application using net beans.http://www.netbeans.org/kb/41/hibernate.html ...
Read Answers (1) | Asked by : Hem

Latest Answer: cascade specifies which operations should be casecaded from the parent object to the associated object. The meaningfull values would be persist , merge, delete, save_update, evict , replicate, lock , refresh , all , delete_orphan. ...
Read Answers (4) | Asked by : ravi

Latest Answer: Hibernate is ORM tool used for data persistency.Spring is a framework for enterprise applications with default APIs for presentation, middle tiers and presistence layers and allows to integrate with various presentations, middle tier and presistence APIs ...
Read Answers (1) | Asked by : HARSHAL

Latest Answer: Preserving the data inside a database is database persistence. Persistence is once of the fundamental concepts of application developement. There are many alternatives to implement persistence. Object/relational mapping (ORM) is the technique that Hibernate ...
Read Answers (2) | Asked by : donna

Latest Answer: Its is one of the most popular ORM technology available to date in the market.Java bean is a simple resuble component. There is no persistency on bean hibernate provides the service to make the bean persistent so that we can make use of it. In hibernate ...
Read Answers (4) | Asked by : enjoy

Latest Answer: Hibernate 3.2 ...
Read Answers (2) | Asked by : enjoy

Q1: What is the difference between Hibernate and EJB 2.1? Q2: Which one, among EJB 2.1 and Hibernate, is better?Explain with reason.Q3: When to use EJB 2.1 and when to use Hibernate? Explain with scenarios.
Read Answers (2) | Asked by : Kumar

I am using hibernate.What is the use In Data(POJO) class primary key is sending as an argument with constructor?
View Question | Asked by : Kotireddy

Latest Answer: Hibernate Advantages:Productivity:                Improves the productivity by eliminating the JDBC tedious code.                ...
Read Answers (8) | Asked by : kounteya

I am new to Hibernate.So can any one tell me how to develop a application using Hibernate in the Myeclipse .and also please send me pdf to suddu026@gmail.com.Regards,Sudarshan.
Read Answers (3) | Asked by : Sudarshan..

Latest Answer: Ccreate primary key? Not sure but you can defined it in the hbm file by specifying the field with the primary column in the db. ...
Read Answers (5) | Asked by : satyanarayana

Latest Answer: Hibernate has good connection pooling rather than JDBC. It has has more persistance for OOPs. ...
Read Answers (8) | Asked by : davis

Latest Answer: A component is an object saved as a value, not as a reference A component can be saved directly without needing to declare interfaces or identifier properties Required to define an empty constructor Shared references not supported ...
Read Answers (3) | Asked by : sunils

Latest Answer: Hibernate allows the application developer to concentrate on the business logic instead of writing complex SQLs. Aprt from this hibernate would take care of the database connections and managing connection pools. Hibernate can be used with managed (websphere, ...
Read Answers (6) | Asked by : sunils


How do you handle the situation where persistence class attribute name is one of the reserved keyword in database; e.g. user ? Will this cause any issue while hibenrate executes SQL statements behind the scene?
Read Answers (4) | Asked by : sunils

Latest Answer: A component is a contained object that is persisted as a value type ,not an entity reference.eg)public class person{private Name name;public Name getName(){ return name;}public void setName(Name name){this.name=name;}.....}public class Name{chat initial;String ...
Read Answers (1) | Asked by : sunils

Latest Answer: first things first ..i have just seen ppl venting thier personal grudge over java / jpa or whatever over this forum.suns official sacceptence that jpa is a failure. please lets keep it out.as for the answer , JPA is a specification , its nt a frame work ...
Read Answers (5) | Asked by : sunils

Latest Answer: Lazy loading is the responsibility is that to load the objects for its parentIn mapping file, if you want to load the child objects while loading the parent it will wont load coz by default load = trueso you have to specify lazy = falsehere child ...
Read Answers (6) | Asked by : j2eeinterviewee

What are the types of inheritence models and describe how they work like vertical inheritence and horizontal
Read Answers (3) | Asked by : James

Complete Hibernate 3.0 Tutorial

This tutorial provide step by step instructions on using Hibernate 3.0. Hibernate is popular open source object relational mapping tool for Java platform. It provides powerful, ultra-high performance object/relational persistence and query service for Java. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework. The Hibernate Query Language, designed as a "minimal" object-oriented extension to SQL, provides an elegant bridge between the object and relational worlds. Hibernate also allows you to express queries using native SQL or Java-based Criteria and Example queries. Hibernate is now the most popular object/relational mapping solution for Java. Download Source Code Example of tutorial
  1. Introduction to Hibernate 3.0
    This lesson introduces you with the Hibernate 3.0 and provides the detailed features of the Hibernate 3.0
     
  2. Hibernate Architecture
    In this lesson you will learn the architecture of Hibernate.
     
  3. First Hibernate Application
    This section describes you how to develop sample Hibernate Application. Also see Hibernate Getting Started Tutorial.
      
  4. Running the Example in Eclipse
    This section shows you how to run the example in the Eclipse.
     
  5. Understanding Hibernate O/R Mapping
    This section describes the each component of the hibernate mapping file..
     
  6. Understanding Hibernate <generator> element
    In this lesson you will learn about hibernate <generator> method in detail. Hibernate generator element generates the primary key for new record.
     
  7. Using Hibernate <generator> to generate id incrementally
    In this lesson I will show you how to write running program to demonstrate it.
       
  8. Hibernate Update Query
    In this tutorial we will show how to update a row with new information by retrieving data from the underlying database using the hibernate. Lets first write a java class to update a row to the database.
           
  9. Hibernate Delete Query
    In this lesson we will show how to delete rows from the underlying database using the hibernate. Lets first write a java class to delete a row from the database.
           

    Hibernate Query Language
  10. Introduction to Hibernate Query Language
    In this lesson you will learn about Hibernate Query Language and its features.
     
  11. Preparing table for HQL Examples
    In this lesson you will create insurance table and populate it with the data for future examples.
     
  12. Developing POJO class
    In this lesson we will write the java class and add necessary code in the contact.hbm.xml file.
     
  13. HQL from Clause Example
    The from clause is the simplest possible Hibernate Query. In this example you will learn how to use the HQL from clause.
     
  14. HQL Select Clause Example
    In this lesson we will write example code to select the data from Insurance table using Hibernate Select Clause.
       
  15. Hibernate Count Query
    In this section we will show you, how to use the Count Query. Hibernate supports multiple aggregate functions. when they are used in HQL queries, they return an aggregate value (such as sum, average, and count) calculated from property values of all objects satisfying other query criteria.
            
  16. Hibernate Avg() Function (Aggregate Functions)
    In this section, we will show you, how to use the avg() function. Hibernate supports multiple aggregate functions. When they are used in HQL queries, they return an aggregate value ( such as
    avg(...), sum(...), min(...), max(...) , count(*), count(...), count(distinct ...), count(all...) ) calculated from property values of all objects satisfying other query criteria.
           
  17. Hibernate Max() Function (Aggregate Functions)
    In this section, we will show you, how to use the Max() function. Hibernate supports multiple aggregate functions.
       
  18. Hibernate Min() Function (Aggregate Functions)
    In this section, we will show you, how to use the Min() function. Hibernate supports multiple aggregate functions.
           
  19. HQL Where Clause Example
    Where Clause is used to limit the results returned from database. In this lesson you will learn how to use HQL Where Clause.
       
  20. HQL Group By Clause Example
    Group by clause is used to return the aggregate values by grouping on returned component. In this lesson you will learn how to use HQL Group By Clause.
     
  21. HQL Order By Example
    Order by clause is used to retrieve the data from database in the sorted order by any property of returned class or components. In this lesson you will learn how to use HQL Order By Clause.
      

    Hibernate Criteria Query
  22. Hibernate Criteria Query Example
    In this lesson you will learn how to use Hibernate Criteria Query.
     
  23. Narrowing the result set
    In this lesson you will learn how to use Hibernate Criteria Query to narrow down the result data.
      
  24. Hibernate's Built-in criterion: Between (using Integer)
    In this tutorial,, you will learn to use "between" with the Integer class. "Between" when used with the Integer object, It takes three parameters e.g. 
    between("property_name",min_int,max_int).
        
  25. Hibernate's Built-in criterion: Between (using Date)
    In this section, you will learn to use "between" i.e.one of the built-in hibernate criterions. Restriction  class  provides built-in criterion via static factory methods.
          
26.  Hibernate Criteria Expression (eq)
In this section, you will learn to use the "eq" method. This is one of the most important  method that is used to apply
an "equal" constraint to the named property.
      
  1. Hibernate Criteria Expression (lt)
    In this section, you will learn to use the "lt" method. This is one of the most important  method that is used to apply
    a "less than" constraint to the named property.
          
  2. Hibernate Criteria Expression (le)
    In this section, you will learn to use the "le" method. This is one of the most important  method that is used to apply
    a "less than or equal" constraint to the named property.
          
  3. Hibernate Criteria Expression (gt)
    In this section, you will learn to use the "gt" method. This is one of the most important  method that is used to apply
    a "greater than" constraint to the named property
         
  4. Hibernate Criteria Expression (ge)
    In this section, you will learn to use the "ge" method. This is one of the most important  method that is used to apply
    a "greater than or equal" constraint to the named property.
         
  5. Hibernate Criteria Expression (and)
    In this section, you will learn to use the "and" method. This is one of the most important  method that returns the conjunctions of two expressions. You can also build the nested expressions using 'and' and 'or'.
         
  6. Hibernate Criteria Expression (or)
    In this section, you will learn to use the "or" method. This is one of the most important  method that returns the disjunction of the two expressions. You can also build the nested expressions using 'and' and 'or'.
                  
33.  Insert Data into Database Using Hibernate Native SQL
In this example we will show you how you can use Native SQL with hibernate. You will learn how to use Native to insert data into database. Native SQL is handwritten SQL for all database operations like insert, update, delete and select.          
  1. Hibernate Native SQL Example
    Native SQL is handwritten SQL for all database operations like create, update, delete and select. Hibernate Native Query also support stored procedures.
          
  2. Associations and Joins
    This section includes a brief introduction about Associations and Joins along with examples.
                   
  3. Hibernate Aggregate Functions (Associations and Joins)
    This example tries to make understand about the aggregate function of Hibernate with the help of example.
              
  4. Hibernate Subqueries
    In this section, you will learn about the subqueries with an appropriate example.

     
    Hibernate Projections Tutorials and Examples
  5. Hibernate Projections
    In this section, you will learn about the hibernate projections with an appropriate example.
        
  6. Hibernate Projections (rowCount or countDistinct)
    In this section, you will learn about the hibernate projection with an example. Projection Interface: This is an interface that extends the Serializable.
             
  7. Hibernate Projection Count
    In this section, you will learn to hibernate projection count. The example demonstrates the rowCount() method of the projection interface.
        
  8. Hibernate Projection Example (Sum)
    In this section, you will learn to hibernate aggregate function like: sum() using hibernate projection.
                                 
  9. Hibernate How To?
     
  10. Hibernate types
    This section gives you description of all the Types that are supported by Hibernate. A Hibernate Type is used to map a Java property type to a JDBC type or types.
      
  11. Hibernate Books
    List of many best hibernate books.
Hibernate Mapping
In this Hibernate Mapping tutorials series you will learn Hibernate in depth. We will show everything on Hibernate Mappings with running code example.

About Author
Struts Hibernate Integration Tutorial NEW
In this tutorial I will show you how to integrate Struts and Hibernate. After completing this tutorial you will be able to use Hibernate in your Struts project. Download the source code of Struts Hibernate Integration Tutorial.

  1. Setting up MySQL Database and table
    This section describes how to setup database and populate it with the data. We are using MySQL Database for this tutorial.
      
  2. Downloading Struts, Hibernate and Integrate It
    This section explains you to setup the develop workbench for our Struts Hibernate tutorial
      
  3. Writing Hibernate configuration file, POJO class and Tutorial.hbm.xml (Hibernate mapping class)
    In this section we will write required hibernate objects like configuration files and then integrate all the stuffs.
      
  4. Developing Hibernate Struts Plugin
    In this section we will write Hibernate Struts Plugin Java code and integrate it with the Struts.
     
  5. Writing Web Client to Search the database using Struts Hibernate Plugin
    In this section we will write web client to test struts Plugin. We will be developing a search form to search the tutorials from the table.
     
  6. Build and testing the application
    In this section we will build our Struts Hibernate Plugin Application and then test.
     
    Hibernate Annotations
  7. Hibernate Annotations
    Hibernate Annotations examples and tutorials.
      
  8. Quick Hibernate Annotation Tutorial
    This tutorial covers only the Annotations part. The reader must have hands on experience before starting this tutorial.

1.What is ORM ?
ORM stands for object/relational mapping. ORM is the automated persistence of objects in a Java application to the tables in a relational database.

2.
What does ORM consists of ?
An ORM solution consists of the followig four pieces:
  • API for performing basic CRUD operations
  • API to express queries refering to classes
  • Facilities to specify metadata
  • Optimization facilities : dirty checking,lazy associations fetching
3.What are the ORM levels ?
The ORM levels are:
  • Pure relational (stored procedure.)
  • Light objects mapping (JDBC)
  • Medium object mapping
  • Full object Mapping (composition,inheritance, polymorphism, persistence by reachability)
4.What is Hibernate?
Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map plain old Java objects to relational database tables using (XML) configuration files.Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks.

5.
Why do you need ORM tools like hibernate?
The main advantage of ORM like hibernate is that it shields developers from messy SQL. Apart from this, ORM provides following benefits:
  • Improved productivity
    • High-level object-oriented API
    • Less Java code to write
    • No SQL to write
  • Improved performance
    • Sophisticated caching
    • Lazy loading
    • Eager loading
  • Improved maintainability
    • A lot less code to write
  • Improved portability
    • ORM framework generates database-specific SQL for you
6.What Does Hibernate Simplify?
Hibernate simplifies:
  • Saving and retrieving your domain objects
  • Making database column and table name changes
  • Centralizing pre save and post retrieve logic
  • Complex joins for retrieving related items
  • Schema creation from object model
7.What is the need for Hibernate xml mapping file?
Hibernate mapping file tells Hibernate which tables and columns to use to load and store objects. Typical mapping file look as follows:
Hibernate Mapping file

8.
What are the most common methods of Hibernate configuration?
The most common methods of Hibernate configuration are:
  • Programmatic configuration
  • XML configuration (hibernate.cfg.xml)

9.
What are the important tags of hibernate.cfg.xml?
Following are the important tags of hibernate.cfg.xml:
hibernate.cfg.xml

10.
What are the Core interfaces are of Hibernate framework?
The five core interfaces are used in just about every Hibernate application. Using these interfaces, you can store and retrieve persistent objects and control transactions.
  • Session interface
  • SessionFactory interface
  • Configuration interface
  • Transaction interface
  • Query and Criteria interfaces

11.What role does the Session interface play in Hibernate?
The Session interface is the primary interface used by Hibernate applications. It is a single-threaded, short-lived object representing a conversation between the application and the persistent store. It allows you to create query objects to retrieve persistent objects.

Session session = sessionFactory.openSession();
Session interface role:
  • Wraps a JDBC connection
  • Factory for Transaction
  • Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier

12.
What role does the SessionFactory interface play in Hibernate?
The application obtains Session instances from a SessionFactory. There is typically a single SessionFactory for the whole application—created during application initialization. The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime. It also holds cached data that has been read in one unit of work and may be reused in a future unit of work

SessionFactory sessionFactory = configuration.buildSessionFactory();

13.What is the general flow of Hibernate communication with RDBMS?
The general flow of Hibernate communication with RDBMS is :
  • Load the Hibernate configuration file and create configuration object. It will automatically load all hbm mapping files
  • Create session factory from configuration object
  • Get one session from this session factory
  • Create HQL Query
  • Execute query to get list containing Java objects

14.
What is Hibernate Query Language (HQL)?
Hibernate offers a query language that embodies a very powerful and flexible mechanism to query, store, update, and retrieve objects from a database. This language, the Hibernate query Language (HQL), is an object-oriented extension to SQL.

15.
How do you map Java Objects with Database tables?
  • First we need to write Java domain objects (beans with setter and getter).
  • Write hbm.xml, where we map java class to table and database columns to Java class variables.
Example :
<hibernate-mapping>

  <class name="com.test.User"  table="user">

   <property  column="USER_NAME" length="255" 

      name="userName" not-null="true"  type="java.lang.String"/>

   <property  column="USER_PASSWORD" length="255"

     name="userPassword" not-null="true"  type="java.lang.String"/>

 </class>

</hibernate-mapping>
16.What’s the difference between load() and get()?

load() vs. get() :-

No comments:

Post a Comment