Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Brief Introduction about hibernate

Published in: Technology


  1. 1. Hibernate An object-relational mapping solution for Java
  2. 2. Buzz Words <ul><li>Persistence </li></ul><ul><li>O/R Mapping ( Object-Relational mapping ) </li></ul>
  3. 3. What Is Persistence ? <ul><li>The storage of an object on a disk or other permanent storage device or data that exists from session to session </li></ul><ul><ul><li>as opposed to transient data </li></ul></ul><ul><li>Persistent data typically implies that it is durable (i.e. will survive a crash or shutdown of the process) usually with some guarantee of integrity </li></ul><ul><li>Persistence generally implies use of a database </li></ul><ul><ul><li>One could use the file system (with suitably careful procedures) </li></ul></ul>
  4. 4. Persistence Class <ul><li>Default constructor </li></ul><ul><li>Get/set pairs </li></ul><ul><li>Collection property is an interface type </li></ul><ul><li>Identifier property </li></ul>public class AuctionItem { private Long _id; private Set _bids; private Bid _successfulBid private String _description; public Long getId() { return _id; } private void setId(Long id) { _id = id; } public String getDescription() { return _description; } public void setDescription(String desc) { _description=desc; } … }
  5. 5. O/R Mapping <ul><li>Object-Relational mapping (aka O/RM , ORM , and O/R mapping ), is a programming technique for converting data between incompatible type systems in databases and Object-oriented programming languages. In effect, this creates a &quot;virtual object database &quot; which can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools. </li></ul>
  6. 6. O/R Mapping <ul><li>Most business database applications use relational databases </li></ul><ul><li>Need to map the objects in the application to tables in the database </li></ul><ul><li>Sometimes be a simple matter of mapping individual classes to separate database tables </li></ul><ul><li>However, if the class structure is more complex, then the mapping must be carefully considered to allow data to be represented and accessed as efficiently as possible </li></ul>
  7. 7. Object Relational Mapping
  8. 8. O/R Mapping <ul><li>. </li></ul>JavaObject int id; String name; String getName() int getId() void setName(String) void setId(int) SQL Table id [number] primary key, name [varchar(50)] Magic Happens Here (O/R Mapper – i.e. Hibernate)
  9. 9. Who, What, When <ul><li>Officially maintained by Jboss, Inc, started in December, 2001. </li></ul><ul><li>Hibernate is an object-relational mapping (ORM) solution for the Java language. It is free, open source software that is distributed under the GNU Lesser General Public License. It provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database. </li></ul>
  10. 10. History is Awesome! <ul><li>Hibernate was developed by a team of Java software developers around the world led by Gavin King. </li></ul><ul><li>JBoss Group (now part of Red Hat) later hired the lead Hibernate developers and worked with them in supporting Hibernate. This move brought Hibernate development under Java EE Specifications. </li></ul><ul><li>The current version of Hibernate is Version 3.1, which enriched the platform with new features like a new Interceptor/Callback architecture, user defined filters, and JDK 5.0 Annotations (Java's metadata feature). Hibernate 3 is also very close to the EJB 3.0 specification (although it was finished before the EJB 3.0 specification was released by the Java Community Process) and serves as the backbone for the EJB 3.0 implementation of JBoss. </li></ul>
  11. 11. Architecture <ul><li>Hibernate basically sits between the DB and your code </li></ul><ul><li>Can map persistent objects to tables </li></ul>
  12. 12. Why Hibernate ? <ul><li>The purpose of Hibernate is to relieve the developer from a significant amount of common data persistence-related programming tasks. Hibernate adapts to the developer's development process, whether starting from scratch or from a legacy database. </li></ul><ul><li>Minimize database access with smart fetching strategies </li></ul><ul><li>Opportunities for aggressive caching </li></ul><ul><li>Structural mapping more robust when object/data model changes </li></ul>
  13. 13. Why Hibernate ? <ul><li>Minimizes Code </li></ul><ul><li>Does not require a container </li></ul><ul><li>Model is not tied to persistence implementation </li></ul>
  14. 14. Features <ul><li>Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC. 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. </li></ul>
  15. 15. Features <ul><ul><li>HibernateDaoSupport – superclass, easy HibernateTemplate access </li></ul></ul><ul><ul><li>Database independence - sits between the database and your java code, easy database switch without changing any code </li></ul></ul><ul><ul><li>Object / Relational Mapping (ORM) - Allows a developer to treat a database like a collection of Java objects </li></ul></ul><ul><ul><li>Object oriented query language (HQL) - *Portable* query language, supports polymorphic queries etc. </li></ul></ul><ul><ul><li>You can also still issue native SQL, and also queries by “Criteria” (specified using “parse tree” of Java objects) </li></ul></ul><ul><ul><li>Hibernate Mapping - Uses HBM XML files to map value objects (POJOs) to database tables </li></ul></ul><ul><ul><li>Transparent persistence - Allows easy saves/delete/retrieve for simple value objects </li></ul></ul><ul><ul><li>Very high performance “in general” due to intelligent (2-level) caching, although in a few cases hand-written SQL might beat it </li></ul></ul>
  16. 16. Hibernate's Goal <ul><li>Remove 95% of common data persistence problems </li></ul>
  17. 17. Advantages <ul><li>Support for Query Language </li></ul><ul><li>Database Dependent Code </li></ul><ul><li>Maintenance Cost </li></ul><ul><li>Optimize Performance </li></ul><ul><li>Automatic Versioning and Time Stamping </li></ul><ul><li>Open-Source, Zero-Cost Product License </li></ul><ul><li>Scalable </li></ul>
  18. 18. Disadvantages <ul><li>Steep Learning Curve </li></ul><ul><li>Use of Hibernate is an overhead for the applications which are : </li></ul><ul><li>• simple and use one database that never change </li></ul><ul><li>• need to put data to database tables, no further SQL queries </li></ul><ul><li>• there are no objects which are mapped to two different tables Hibernate increases extra layers and complexity. So for these types of applications JDBC is the best choice. </li></ul>
  19. 19. Disadvantages <ul><li>Support for Hibernate on Internet is not sufficient. </li></ul><ul><li>Hibernate does not allow some type of queries which are supported by JDBC. For example It does not allow to insert multiple objects (persistent data) to same table using single query. Developer has to write separate query to insert each object. </li></ul>