Saturday, June 17, 2017

Top Hibernate interview questions and answer part 1



1) What are the problems of jdbc?

   a) we must manually handle database connections. There is always risk with connection leakage.

   b) We have to write many lines of code if we have more number of fields in inserts, updates.
       When we perform object persistence, we need to copy the properties of object to paramets in               prepared statement.

   c) The code cannot be portable to other databases.The sql statements written for one database                   cannot be portable to other database.

   d) We must manually handle associations. When you perform object retrieval, you have to perform         a table join or read from several tables to get an object graph. When you perform object                       persistence, you must update several tables accordingly.


2) What is ORM? Explain its benefits and drawbacks?

       Object/relational mapping is the automated (and transparent) persistence of objects in a Java                application to the tables in a relational database,using metadata.

  The metadata describes the mapping  between the objects and the database.Using ORM, the                  application interacts with the ORM APIs and the domain model classes and is 
  abstracted from the underlying SQL/JDBC.

      Here are some of the benefits of ORM framework:
      Productivity:
      ORM reduces the development time as it eliminates the most of work.

        Maintainability:
        Because much of the work is done through configuration, your code has fewer lines and thus               requires less maintenance

       Vendor Independent :An ORM abstracts your application away from the underlying SQL                      database and  SQL dialect.ORM gives portability to support multiple databases.

       Reduce Complexity :
       ORM relieves the job of developer 95 percent of object persistence work, such as writing                     complex SQL statements with many table joins and 
        copying values from JDBC result sets to objects or graphs of objects.

 Here are the drawbacks of ORM framework :
      a) Slow Performance : For batch updates performance is slower.
      b) Overhead : For simple applications with basic curd operations that use single database it                       becomes extra overhead for them.
      c) Learning : Developer has to learn a new framework.

No comments:

Post a Comment

Popular Posts