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.
21. What is Attribute Oriented Programming?
XDoclet has brought the concept of attribute-oriented programming to Java. Until JDK 1.5, the Java language had no support for annotations; now XDoclet uses the Javadoc tag format (@attribute) to specify class-, field-, or method-level metadata attributes. These attributes are used to generate hibernate mapping file automatically when the application is built. This kind of programming that works on attributes is called as Attribute Oriented Programming.
22. What is component mapping in hibernate?
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 first;
String last;
public char getInitial(){return initial;}
public void setInitial(char initial){this.initial=initial;}
.......//first,last
}
Now 'Name' may be persited to the component of 'person'
in hbm:
The person table would have the columns pid, birthday, initial, first and last.
23. What is database persistence? How well it is implemented in Hibernate
Preserving the data inside a database is database persistence. Persistence is once of the fundamental concepts of application development.
There are many alternatives to implement persistence. Object/relational mapping (ORM) is the technique that Hibernate tool uses to persist the data. By using ORM tool like Hibernate, you get advantages like low SQL coding (improved productivity), easy to maintain the system and also leads to better performance.
24. What is Hibernate proxy?
Proxies are created dynamically by sub classing 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
25. What is Hibernate?
Hibernate is a powerful, high performance object/relational persistence and query service. This lets the users to develop persistent classes following object-oriented principles such as association, inheritance, polymorphism, composition, and collections.
26. What is HQL?
HQL stands for Hibernate Query Language. Hibernate allows the user to express queries in its own portable SQL extension and this is called as HQL. It also allows the user to express in native SQL.
27. what is lazy fetching in hibernate?
There are two types of Loading in application. Eager loading and Lazy
loading. In eager loading we will fetch all the values from the Persistent storage and cache it. It will make serious performance issues. We use lazy loading to avoid that scenario.
Lazy setting decides whether to load child objects while loading the Parent Object. You need to do this setting respective hibernate mapping file of the parent class.Lazy = true (means not to load child) ( In the terms of database its primary key-foreign key relationship).
By default the lazy loading of the child objects is true. This make sure that the child objects are not loaded unless they are explicitly invoked in the application by calling getChild() method on parent. In this case hibernate issues a fresh database call to load the child when getChild() is actually called on the Parent object. But in some cases you do need to load the child objects when parent is loaded. Just make the lazy=false and hibernate will load the child when parent is loaded from the database
But Sometimes it doesn't work properly, it doesn't load the child objects for the parent .and second problem is that if you have condition like ....
Employee Table -1-----n-> Emp_Dept Table<-n------1- Department Table
And you have many to many relationship between them, then by specifying lazy="false" for both the parent object(Employee And Department) hibernate try to get all the child for this parent and for this child. Now this child becomes the parent and hibernate will try to get the entire child for this parent. This process may continue. This results in performance issue.
So U has to take care while writing the mapping files in case of many-to-many relationships.
28. What is meant by full object mapping?
Full object mapping supports sophisticated object modeling: composition, inheritance, polymorphism and persistence. The persistence layer implements transparent persistence; persistent classes do not inherit any special base class or have to implement a special interface. Efficient fetching strategies and caching strategies are implemented transparently to the application.
29. What is meant by Method chaining?
Method chaining is a programming technique that is supported by many hibernate
interfaces. This is less readable when compared to actual java code. And it is not
mandatory to use this format. Look how a SessionFactory is created when we use method
chaining.
SessionFactory sessions = new Configuration()
.addResource("myinstance/MyConfig.hbm.xml")
.setProperties( System.getProperties() )
.buildSessionFactory();
30. What is object/relational mapping metadata?
ORM tools require a metadata format for the application to specify the mapping between classes and tables, properties and columns, associations and foreign keys, Java types and SQL types. This information is called the object/relational mapping metadata. It defines the transformation between the different data type systems and relationship representations.