Slideshow transcript
Slide 1: Hibernate An object-relational mapping solution for Java
Slide 2: Buzz Words Persistence O/R Mapping (Object-Relational mapping )
Slide 3: What Is Persistence ? The storage of an object on a disk or other permanent storage device or data that exists from session to session as opposed to transient data 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 Persistence generally implies use of a database One could use the file system (with suitably careful procedures)
Slide 4: Persistence Class public class AuctionItem { private Long _id; Default private Set _bids; constructor private Bid _successfulBid private String _description; Get/set pairs public Long getId() { Collection return _id; property is an } private void setId(Long id) { interface type _id = id; } Identifier public String getDescription() { property return _description; } public void setDescription(String desc) { _description=desc; } … }
Slide 5: O/R Mapping 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 "virtual object database" 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.
Slide 6: O/R Mapping Most business database applications use relational databases Need to map the objects in the application to tables in the database Sometimes be a simple matter of mapping individual classes to separate database tables 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
Slide 7: Object Relational Mapping
Slide 8: O/R Mapping . JavaObject SQL Table int id; String name; id [number] primary String getName() int getId() key, void setName(String) name [varchar(50)] void setId(int) Magic Happens Here (O/R Mapper – i.e. Hibernate)
Slide 9: Who, What, When Officially maintained by Jboss, Inc, started in December, 2001. 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.
Slide 10: History is Awesome! Hibernate was developed by a team of Java software developers around the world led by Gavin King. 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. 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.
Slide 11: Architecture • Hibernate basically sits between the DB and your code • Can map persistent objects to tables
Slide 12: Why Hibernate ? 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. Minimize database access with smart fetching strategies Opportunities for aggressive caching Structural mapping more robust when object/data model changes
Slide 13: Why Hibernate ? • Minimizes Code • Does not require a container • Model is not tied to persistence implementation
Slide 14: Features 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.
Slide 15: Features HibernateDaoSupport – superclass, easy HibernateTemplate access Database independence - sits between the database and your java code, easy database switch without changing any code Object / Relational Mapping (ORM) - Allows a developer to treat a database like a collection of Java objects Object oriented query language (HQL) - *Portable* query language, supports polymorphic queries etc. You can also still issue native SQL, and also queries by “Criteria” (specified using “parse tree” of Java objects) Hibernate Mapping - Uses HBM XML files to map value objects (POJOs) to database tables Transparent persistence - Allows easy saves/delete/retrieve for simple value objects Very high performance “in general” due to intelligent (2-level) caching, although in a few cases hand-written SQL might beat it
Slide 16: Hibernate's Goal • Remove 95% of common data persistence problems
Slide 17: Advantages Support for Query Language Database Dependent Code Maintenance Cost Optimize Performance Automatic Versioning and Time Stamping Open-Source, Zero-Cost Product License Scalable
Slide 18: Disadvantages Steep Learning Curve Use of Hibernate is an overhead for the applications which are : • simple and use one database that never change • need to put data to database tables, no further SQL queries • 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.
Slide 19: Disadvantages Support for Hibernate on Internet is not sufficient. 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.





Add a comment on Slide 1
If you have a SlideShare account, login to comment; else you can comment as a guest- Favorites & Groups
Showing 1-50 of 2 (more)