Hibernate Event System

In this tutorial you will learn about the Event system in Hibernate.


 

Ads

Tutorials   
How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate 4.3.4 Released: Hibernate 4.3.4.Final Maven dependency Hibernate 4.3 Hello World: Example How to create SessionFactory in Hibernate 4.3.1? Hibernate 4 Hello World: Example of Hello World program Hibernate 4 create Session Factory: Example of creating Session Factory in Hibernate 4 Hibernate 4.3 and JPA 2.1 Example What is Hibernate in Java? Hibernate Overview and Architecture What is JPA 2.1? Hibernate 4.3.0.Final Maven dependency Hibernate 4.3 ORM Features Hibernate 4.3 Tutorial Hibernate Criteria average example Hibernate Criteria load all objects from table Hibernate Criteria Hibernate beginner tutorial Hibernate Session.delete() Example Hibernate save or update method example Hibernate Load Example Hibernate save Example - Rose India Hibernate 4 tutorials Hibernate Example Step by Step in Eclipse Hibernate Configuration files Setup Hibernate Environment Hibernate Architecture Hibernate Overview Hibernate 4.2 Tutorial Hibernate 4 Annotations Tutorial Hibernate 4 AnnotationSessionFactoryBean hibernate versions hibernate jndi hibernate tomcat hibernate metamodel generator hibernate entity Seam Hibernate C3P0 Hibernate hibernate shard hibernate means temporal hibernate jsf hibernate spring j2ee hibernate spring hibernate encrypted password alias_to_entity_map hibernate temporal jsf spring hibernate hibernate by example hibernate repository hibernate sample code
Ads

Hibernate Event System

In this tutorial you will learn about the Event system in Hibernate.

As concerned to Event it can be said that Event has replace the Interceptor however, it is added as an additional functionality to intercept pre-requisite or post-requisite operations before or after the functional logic. Hibernate 4 event architecture allows to work with the particular events at a persistence layer. Several Session interface's methods are mutually related to an event type. org.hibernate.event.spi.EventType class contains the a full scale defined event types that are declared as an enum values. It works when a request is made for one of these methods an event is generated by Hibernate Session and is passed to the appropriate EventListener that are set up for that event type. In Hibernate a custom listener is also allowed, in custom listener for an event (want to process) an appropriate interface is need to be implemented.

List of Some EventListener are :

  • AutoFlushEventListener
  • DeleteEventListener
  • PostDeleteEventListener
  • PreDeleteEventListener
  • InitializeCollectionEventListener
  • LoadEventListener
  • MergeEventListener
  • PostInsertEventListener
  • PreInsertEventListener
  • SaveOrUpdateEventListener : save, update, saveupdate

Example :

import java.util.Set;

import org.hibernate.HibernateException;
import org.hibernate.event.spi.DeleteEvent;
import org.hibernate.event.spi.DeleteEventListener;

public class MyListener implements DeleteEventListener
{

@Override
public void onDelete(DeleteEvent event) throws HibernateException {
System.out.println("deleted successfully");

}

@Override
public void onDelete(DeleteEvent event, Set set) throws HibernateException {

System.out.println("Set is deleted successfully");
}

}

The example given above is demo example it only demonstrate you how a custom listener can be created.

Advertisements

Ads
Share on Google+Share on Google+

Hibernate Event System

Posted on: March 15, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Hibernate Event System  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads