Hibernate's primary feature is mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. Hibernate generates the SQL calls and relieves the developer from manual result set handling and object conversion, keeping the application portable to all SQL databases, with database portability delivered at very little performance overhead.
Hibernate provides transparent persistence for Plain Old Java Objects (POJOs). The only strict requirement for a persistent class is a no-argument constructor, not compulsorily public. (Proper behavior in some applications also requires special attention to the equals() and hashCode() methods.)
Hibernate provides a dirty checking feature that avoids unnecessary database write actions by performing SQL updates only on the modified fields of persistent objects.
Hibernate can be used both in standalone Java applications and in Java EE applications using servlets or EJB session beans.
31. What is ORM?
ORM stands for Object/Relational mapping. It is the programmed and translucent perseverance of objects in a Java application in to the tables of a relational database using the metadata that describes the mapping between the objects and the database. It works by transforming the data from one representation to another.
32. what is the advantage of Hibernate over jdbc?
The core drawback of JDBC is that it doesn'tallow you to store objects directly to the database you must convert theobjects to a relational format.
"Write Once persist anywhere" using hibernate can achieved by changing the dialect in configuration xml file. Where as in JDBC we need to change the code.
33. What is the difference between and merge and update
The merge() method merges modifications made to the detached instance into the corresponding managed instance, if any, without consideration of the state of the persistence context
Usually merge() is used in the following scenario:
the application loads an object in the first entity manager
the object is passed up to the presentation layer
some modifications are made to the object
the object is passed back down to the business logic layer
the application persists these modifications by calling merge() in a second entity manager
34. What is the difference between Hibernate and EJB 2.1? Which one, among EJB 2.1 and Hibernate, is better? Explain with reason. When to use EJB 2.1 and when to use Hibernate? Explain with scenarios
| EJB | Hibernate |
| Though ejb entity bean is used for object oriented view it does not support POLYMORPHISM and INHERITANCE | supports both |
| Persistence management is handled by JDBC . Sql queries are tough | Insert (),Save(),etc methods available.Low sql coding |
| Uses Container services for transaction,security etc | Container is not needed |
35. what is the difference between hibernate and Spring
Hibernate is ORM tool used for data persistency.
Spring is a framework for enterprise applications with default APIs for presentation, middle tiers and persistence layers and allows to integrate with various presentations, middle tier and persistence APIs like Hibernate, Struts, Ibatis, JMS, MQ series etc.
36. What is the difference between sorted and orderd collection in hibernate?
A sorted collection is sorted in-memory using java comparator, while order collection is ordered at the database level using order by clause.
For Sorted Collection:
A sorted collection is sorting a collection by utilizing the sorting features provided by the java collections framework. If your collection is not large, it will be more efficient way to sort it.
For Ordered Collection:
Order collection is sorting a collection by specifying the order-by clause for sorting this collection when retrieval. If your collection is very large, it will be more efficient way to sort it .
37. What is the file extension you use for hibernate mapping file?
The name of the file should be like this : filename.hbm.xml The filename varies here. The extension of these files should be ?.hbm.xml?. This is just a convention and it?s not mandatory. But this is the best practice to follow this extension.
38. what is the latest version of Hibernate using in current industry?
Hibernate3.0 Hibernate 3.2
39. what is the main advantage of using the hibernate than using the sql?
1. Hibernate is based on object oriented concept like java. so it has better compatibility with java than sql.
2.Main advantage is that it avoids writing querries. Ofcourse, u have to write to some extent but alot is relaxed. criteria class is very useful for complex joins.
3.Easily migrate your code between different databases. Good for updating, maintainning your application
4. Here there is no need to write the jdbc code here we will use the connection pooling technique and it happens internally and because of connection pooling we can reuse the connection from the pool. In Jdbc we have to mannualy handle exception and every time we need to open/cose the connection,create/close the statement , resultset whatever we have used
40. what is the use of cascade in hbm file?
cascade (optional): Specifies which operations should be cascaded from the parent object to the associated object.
1) cascade ="none",
the default, tells Hibernate to ignore the association.
2) cascade ="save-update"
tells Hibernate to navigate the association when the transaction is committed and when an object is passed to save() or update() and save newly instantiated transient instances and persist changes to detached instances.
3) cascade ="delete"
tells Hibernate to navigate the association and delete persistent instances when an object is passed to delete().
4) cascade ="all"
means to cascade both save-update and delete, as well as calls to evict and lock.
5) cascade ="all-delete-orphan"
means the same as cascade="all" but, in addition,
Hibernate deletes any persistent entity instance that has been removed
(dereferenced) from the association (for example, from a collection).
6) cascade="delete-orphan" Hibernate will delete any persistent entity
instance that has been removed (dereferenced) from the association (for
example, from a collection).