Hibernate Framework Basic

This entry is part 1 of 13 in the series Hibernate Tutorial

What is Hibernate

Hibernate is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions.

Hibernate facilitates the storage and retrieval of Java domain objects via Object/Relational Mapping.

What Hibernate Does

  • Map Java class to database tables & vice versa
  • Data query and retrieval facility
  • Generate the SQL query based on the underline DB. and attempts to relieve the developer from manual result set handling and object conversion.
  • Make application portable to all relational DB.
  • Enhance performance by providing the different levels of cache(First, Second and Query level).

What is HQL

HQL is abbreviation of Hibernate Query Language. It is SQL inspired language provided by hibernate. Developer can write SQL like queries to work with data objects.

What is Dialect

Each SQL vendor has its own set of supported syntax. This is known as dialect. In order to generate appropriate sql query Hibernate needs to know, for which DB query needs to be generated. Hibernate does it by org.hibernate.dialect.Dialect class and its subclass for each vendor.

E.g.:

DB2       :   org.hibernate.dialect.DB2Dialect

MySQL  :   org.hibernate.dialect.MySQLDialect

Connection Pooling

Hibernate has its own internal connection pooling but it also support some third party connection pooling for production use.

  • c3p0 connection pool
  • Proxool connection pool
  • Obtaining connections from an application server, using JNDI

Hibernate Association

What is Hibernate Association: Any Table in DB could be connected to other tables in same or other DB. And these tables could be associated with each other via some keys(Foreign..). Those kind of scenario can be handled with association.

E.g: There are 2 table in DB, Student  & Subject. A student can study one subject or more then one subject. In that case every student will have only one entry in Student table but Subject table could contain more than one record for corresponding record in Student table.

Association mapping are used to map a Java Object to DB table.

Entities envoled in mappings:

  • Class (Persistence)(POJO)
  • DB Table
  • Mapping file(.hbm)

Rules associated to POJO:

  • POJO class needs to have default constructor as it is required by Hibernate.
  • Lazy loading doesn’t work with Final class. Its preferable to have Non Final classes.

Type of Association

Unidirectional Association:

  • Many To One
  • One to One
  • One to Many

Unidirectional Association with join Table

  • Many To One
  • One to One
  • One to Many
  • Many to Many

Bidirectional Association

  • One to Many / Many to One
  • One to One

Bidirectional Association with join Table

  • One to Many / Many to One
  • One to One
  • Many to Many
Series NavigationHibernate 4.3 Introduction Tutorial >>

6 Comments Hibernate Framework Basic

  1. abhay

    Content are all fine..but ,try reducing the usage of hardcore programming terms ..u must try making contents and related technical terms as simple as possible….. ;-)

    Reply
  2. Ramanand

    Hi,
    I am using Hibernate implementation with JPA, while migrating server from Tomcat Openejb to jboss i am getting the below error without proper information in the log file.

    Error : org.hibernate.MappingException: component property not found: id

    please provide the more information on the issue why it’s coming

    Thanks in Advance,
    Ramanand

    Reply
  3. Samrat Ghosh

    Hi,
    I want to learn Hibernate for working on Enterprise Level application in a very short tym span.Can U plz mention what r the topic i must hav to know for cracking interview and working in a project comfortably.

    Thanks in Advnce,
    Samrat Ghosh :)

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *