Sunday 29 September 2013

Top 10 Interview Question and Answers for Spring Hibernate

Leave a Comment
Here this article is about Top 10 Interview Question and Answers for Spring Hibernate which are very useful for the seekers in the future when you attend interview regarding Spring Hibernate. These Question and answers are explained in a brief way and in a simple manner where the readers can understand easily without any difficulties. After reading these please share your testimonial with us. All the best





Introduction to Spring Hibernate

Hibernate and Spring are open source Java frameworks to simplify developing Java/JEE applications from simple, stand-alone applications running on a single JVM, to complex enterprise applications running on full blown application servers. Hibernate and Spring allow developers to produce scalable, reliable, and effective code. Both frameworks support declarative configuration and work with a POJO programming model minimizing the dependence of application code on the frameworks and making development more productive and portable.


1) Define spring?

Ans: Spring performs two major roles for a Java application. Spring is also a framework because it provides libraries of classes that make it easier to accomplish common tasks such as transaction management, database integration, email, and web applications.



2) Define Hibernate?

Ans: It 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, polymorph.



3) What are the different IOC containers available?

Ans: Spring is an IOC container. Other IOC containers are HiveMind, Avalon, PicoContainer.



4) What is difference between sorted and ordered collection in hibernate?

Ans: A sorted collection is sorted in memory by using Java Comparator, while a ordered collection uses database's order by clause for ordering. For large data set it's better to use ordered collection to avoid any Out Of Memory Error in Java, by trying to sort them in memory.



5) What does spring provide?

Ans: Spring is a lightweight framework. Most of your Java classes will have nothing about Spring in their source code.  This means that you can easily transition your application from the Spring framework to something else.  It also means that transferring an existing application to use the Spring framework does not have to mean a complete code rewrite.



6) Explain the major advantages of Hibernate?

Ans: Major advantages of Hibernate are as follows:
Powerful object oriented hibernate query language
Transparent resolution based on POJOs lacking byte code processing
Graphic O/R Mapping during mapping file.
Mechanical chief key generation
Hibernate cache Session Level, Query and Second level cache.
Presentation Lazy initialization, Outer joins attractive, Batch fetching



7) Define ORM?

Ans:  ORM stands for Object Relational mapping. It is the programmed and transparent insistence of objects in a Java application in to the tables of a relational database using the metadata to describes the mapping between the objects and database. It works by transforming the data from one demonstration to another.



8) Why hibernate is more beneficial over Entity Beans & JDBC?

Ans: Entity bean always works under the EJB container, which allows reusing of the object external to the container. An object can not be disconnected in entity beans and in hibernate detached objects are supported. Hibernate is not database dependent where as JDBC is database dependent.  Query tuning is not needed for hibernate as JDBC is needed. Data can be placed in multiple cache which is supported by hibernate.



9) Explain how will you configure Hibernate?

Ans: The configuration files hibernate.cfg.xml and mapping files *.hbm.xml are used by the Configuration class to create the Session Factory, which in turn creates the Session instances. Session instances are the primary border for the persistence service.” hibernate.cfg.xml.



10) Define Hibernate proxy?

Ans: The proxy feature enables lazy initialization of constant instance of the class. Hibernate will originally return CGLIB proxies which execute the named interface. The actual constant object will be loaded when a method of the proxy is invoked.
Read More...