Tuesday 11 December 2012

Differences between Hibernate 2.x and Hibernate 3.x


Some of Key Points Hibernate 2.x V Hibernate 3.x:
  •    Hibernet2.x version increases to Hibernet3.x, that is include
       more features and bug fixes.
  •    Hibernate 3.0 is not source-compatible with Hibernate 2.1.
  •    The changes made in Hibernet3.0 were carefully designed to
       allow straightforward migration of both code and metadata.
  •    It is possible to run Hibernate 2.x and Hibernate 3.x side by
       side in the
    same application. 
Some of Changes made in Hibernate3.x compared with Hibernet2.x:

API Changes:
  •  The Hibernate3 package structure is rooted at org.hibernate 
     instead of net.sf.hibernate.This renaming was done to allow
     Hibernate2 and Hibernate3 to run side by side in the same
     application.
  •  Certain interfaces that have been deprecated in Hibernate3
     were moved to the org.hibernate.classic package.
  •  HibernateException and all other Hibernate exceptions are
     changed in Hibernate3 as a unchecked runtime exceptions.
  •  Compared to Hibernate2 , Hibernate3 provides the
     ParameterizedType interface to allow better re-useability of
     user type implementations.
  •  Hibernate3.x wraps Blob and Clob instances, to allow classes
     with a property of type Blob or Clob
    to be detached,serialized,
     deserialized, and passed to merge(). Hibernate2.x not
     supported this feature.
Metadata Changes :
  • In Hibernate2.x it is best practice to map almost all classes and collections using lazy="true",that is in Hibernate3.x the default feature. In hibernate2.x applications will need to explicitly specify
    lazy="false" on all non-lazy class and collection mappings.
  • In hibernet 3.x The outer-join attribute is deprecated.Use fetch="join" and fetch="select" instead  of outer-join="true" and outer-join="false".
  • The <index> element is semi-deprecated, <list-index> and <map-key> are now preferred In hibernate3.x.
          <map-key-many-to-many> is preferred to <key-many-to-many>.      
          <composite-map-key> is preferred to <composite-index>.
  • DTD reference in hbm XML files is changed in Hibernate 3.x when compared to Hibernate2.x.
 
Query Language Changes :
  •  Hibernate3 comes with a brand-new, ANTLR-based 
     HQL/SQL query translator. However, the Hibernate 2.1
    query 
     parser is still available.
  •  The query parser may be selected by setting the Hibernate 
     property  hibernate.query.factory_class.

Main Advantage Of Hibernates :
  •  Hibernate supports Inheritance, Associations, Collections.
  •   In jdbc all exceptions are checked exceptions, so we must write code in try, catch and throws,but in hibernate we only have    Un-checked exceptions (From Hibernate 3.x), so no need to write try, catch or no need to write throws.
  •   Hibernate has capability to generate primary keys automatically while we are storing the records  into database.
  •   Hibernate has its own query language, i.e hibernate query language which is database independent.
  •   While we are inserting any record, if we don't have any particular table in the database, JDBC will rises an error like "View notexist",and throws exception, but in case of hibernate, if it not found any table in the database this will create the table for us
  •  Hibernate supports caching mechanism by this, the number of round trips between an application and the database will be reduced, by using this caching technique an application performance will be increased automatically.
Disadvantages Of Hibernates :
  • Hibernate is little slower than pure JDBC, actually the reason  being hibernate used to generate many hibernate used to gener ate many SQL statements in run time.
  •   Boilerplate code issue, actually we need to write same code in several files in the same application.


No comments:

Post a Comment