Tolal:100 Click:
1
2 3 4 5
Hiber Interview Questions And Answers
Page 1
Ques: 1
What is Hibernate?
Ans:
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.
Ques: 2
What is Persistence?
Ans:
Persistence is one of the fundamental concepts in application development. In an object-oriented application, persistence allows an object to outlive the process that created it. The state of the object may be stored to disk and an object with the same state re-created at some point in the future.
Persistence is the ability of data to outlive an instance of a program, central to modern applications. Hibernate, the most popular Java persistence tool, provides automatic and transparent object/relational mapping so it's a snap to work with SQL databases in Java applications.
Ques: 3
What is ORM? What does ORM consists of?
Ans:
ORM stands for object/relational mapping. ORM is the automated persistence of objects in a Java application to the tables in a relational database.
An ORM solution consists of the followig four pieces:
* API for performing basic CRUD operations
* API to express ries refering to classes
* Facilities to specify metadata
* Optimization facilities : dirty cecking, lazy associations fetching.
Ques: 4
What Does Hibernate Simplify?
Ans:
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
Ques: 5
What are the most common methods of Hibernate configuration?
Ans:
The two most common methods of Hibernate configuration are:
* Programmatic configuration
* XML configuration (hibernate.cfg.xml)
Ques: 6
What are the Core interfaces are of Hibernate framework?
Ans:
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
Ques: 7
How to call stored procedure in mysql through hibernate?
Ans:
If your stored procedure is returning a value you can directly use <sql-query>, otherwise you need to use jdbc connection to call the native sql procedure.
Example:
Session session = getHibernateTemplate().getSessionFactory().openSession();
/*if you are not using session factory, you can use ur own method to get session.*/
Connection conn = session.connection();
String sqlQuery = "call VersionUpdateProcedure()";
CallableStatement cs = conn.prepareCall(sqlQuery);
cs.execute();
conn.close();
session.close();
Ques: 8
what is lazy initialisation in hibernate?
Ans:
Hibernate supports the feature of lazy initilasation for both entities and collections. What this actually means is, the Hibernate engine loads only those objects that we are querying for and doesnt try to fetch other entities(that are associated with the entity we are querying) or collections.
Hibernate loads collection elements only when actually you ask for them by saying lazy=true or lazy=false.
Example:
<set name="Child" lazy="false" inverse="true">
<key column="COL"/>
<one-to-many class="Parent"/>
</set>
Ques: 9
What is Hibernate proxy?
Ans:
Proxies are the mechanism that allows Hibernate to break up the interconnected cloud of objects in the database into smaller chunks, that can easily fit in memory. Proxies are created dynamically by subclassing your object at runtime. The subclass has all the methods of the parent, and when any of the methods are accessed, the proxy loads up the real object from the DB and calls the method for you. A class can be mapped to a proxy instead to a table. When you actually call load on session it returns you proxy. This proxy may contain actual method to load the data.
Object proxies can be defined in one of two ways. First, you can add a proxy attribute to the class element. You can either specify a different class or use the persistent class as the proxy.
For example:
<class name="Location"
proxy="com.ch01.Location">
</class>
The second method is to use the lazy attribute. Setting lazy="true"is a shorthand way of defining the persistent class as the proxy. Let's assume the Location class is defined as lazy:
<class name="Location"lazy="true"...>...</class>
Ques: 10
What is the main difference between Entity Beans and Hibernate ?
Ans:
In an Entity Bean, we can interact with only one Database at a time. Whereas in Hibernate, we can establishe the connections to more than one Database. Only thing we need to write one more configuration file.
Entity Beans does not support OOPS concepts where as Hibernate does. Hibernate supports multi level cacheing, where as Entity Beans doesn't.
Ques: 11
What role does the Session interface play in Hibernate?
Ans:
The Session is a persistence manager that manages operation like storing and retrieving objects. Instances of Session are inexpensive to create and destroy. They are not threadsafe. 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 ry objects to retrieve persistent objects.
Session session = sessionFactory.openSession();
Session interface play roles in:
* 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.
Ques: 12
How will you configure Hibernate?
Ans:
The configuration files hibernate.cfg.xml (or hibernate.properties) and mapping files *.hbm.xml are used by the Configuration class to create the SessionFactory, which in turn creates the Session instances.
• hibernate.cfg.xml
• Mapping files
These two files are used to configure the hibernate sevice (connection driver class, connection URL, connection username, connection password, dialect etc).
Ques: 13
Is SessionFactory a thread safe object ?
Ans:
Yes! SessionFactory object is threadsafe. Many threads can request for session and immutable cache of compiled mappings for a single database.
Ques: 14
What are different levels of ORM quality?
Ans:
There are four levels defined for ORM quality:
* Pure relational: The entire application, including the UI is designed around the relational model and SQL based relational operation.
* Light Object Mapping: The entities are represented as classes that are mapped manually to the relational tables. The code is hidden from the business logic using specific design patterns.
* Medium Object Mapping: The application is designed around an object model. The SQL code is generated at build time, and the association between objects is supported by the persistence mechanism, and queries are specified using an object-oriented expression language. This is best suited for medium-sized applications with some complex transactions.
* Full Object Mapping: Full Object Mapping supports sophisticated object modeling, composition, inheritance, polymorphism and persistence.
Ans:
There are four levels defined for ORM quality:
* Pure relational: The entire application, including the UI is designed around the relational model and SQL based relational operation.
* Light Object Mapping: The entities are represented as classes that are mapped manually to the relational tables. The code is hidden from the business logic using specific design patterns.
* Medium Object Mapping: The application is designed around an object model. The SQL code is generated at build time, and the association between objects is supported by the persistence mechanism, and queries are specified using an object-oriented expression language. This is best suited for medium-sized applications with some complex transactions.
* Full Object Mapping: Full Object Mapping supports sophisticated object modeling, composition, inheritance, polymorphism and persistence.
Ques: 15
What is Hibernate Query Language (HQL)?
Ans:
Hibernate offers a query language which is powerful and provides flexible mechanism to query, store, update and retrieve objects from database. This HQL is an object oriented extension to SQL. Hibernate query Language (HQL) is an object-oriented extension to SQL.
Ques: 16
What are derived properties?
Ans:
The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties. The expression can be defined using formula attribute of the element.
Ques: 17
How do you map Java Objects with Database tables?
Ans:
First we need to write Java domain objects (beans with setter and getter). The variables should be same as database columns. Write hbm.xml, where we map java class to table and database columns to Java class variables.
Example :
<hibernate-mapping>
<class name="com.User" table="user">
<property column="username" length="255"
name="userName" not-null="true" type="java.lang.String"/>
<property column="userpassword" length="255"
name="userPassword" not-null="true" type="java.lang.String"/>
</class>
</hibernate-mapping>
Ques: 18
What is the general flow of Hibernate communication with RDBMS?
Ans:
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.
Ques: 19
Define HibernateTemplate?
Ans:
The 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.
Ques: 20
How will you obtain a session factory?
Ans:
After all mappings have been parsed by the org.hibernate.cfg.Configuration, the application must obtain a factory for org.hibernate.Session instances. This factory is intended to be shared by all application threads:
SessionFactory sessions = cfg.buildSessionFactory();
Hibernate does allow your application to instantiate more than one org.hibernate.SessionFactory. This is useful if you are using more than one database.
Goto Page:
1
2 3 4 5
Hiber Objective
Hiber Objective Questions And Answers
Hiber Interview Questions And Answers
Hiber Interview Questions And Answers
R4R,Hiber Objective, Hiber Subjective, Hiber Interview Questions And Answers,Hiber,Hiber Interview,Hiber Questions ,Hiber Answers