Hibiscus

A collection of useful Hibernate utilities.

License

License

GroupId

GroupId

com.carmanconsulting.hibiscus
ArtifactId

ArtifactId

hibiscus-parent
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

pom
Description

Description

Hibiscus
A collection of useful Hibernate utilities.
Source Code Management

Source Code Management

https://github.com/carmanconsulting/hibiscus

Download hibiscus-parent

Filename Size
hibiscus-parent-1.1.pom 2 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/com.carmanconsulting.hibiscus/hibiscus-parent/ -->
<dependency>
    <groupId>com.carmanconsulting.hibiscus</groupId>
    <artifactId>hibiscus-parent</artifactId>
    <version>1.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.carmanconsulting.hibiscus/hibiscus-parent/
implementation 'com.carmanconsulting.hibiscus:hibiscus-parent:1.1'
// https://jarcasting.com/artifacts/com.carmanconsulting.hibiscus/hibiscus-parent/
implementation ("com.carmanconsulting.hibiscus:hibiscus-parent:1.1")
'com.carmanconsulting.hibiscus:hibiscus-parent:pom:1.1'
<dependency org="com.carmanconsulting.hibiscus" name="hibiscus-parent" rev="1.1">
  <artifact name="hibiscus-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.carmanconsulting.hibiscus', module='hibiscus-parent', version='1.1')
)
libraryDependencies += "com.carmanconsulting.hibiscus" % "hibiscus-parent" % "1.1"
[com.carmanconsulting.hibiscus/hibiscus-parent "1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.5
org.hibernate : hibernate-core jar 4.2.3.Final
org.hibernate : hibernate-entitymanager Optional jar 4.2.3.Final

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.slf4j : slf4j-log4j12 jar 1.7.5

Project Modules

  • event

Event Listeners

Hibernate event listeners can be very powerful. However, Spring doesn't include a nice way to register Spring-managed beans as Hibernate event listeners. The hibiscus-event library contains utility classes which make it easy to register your Spring-managed beans as Hibernate event listeners.

Writing an Event Listener

Writing an event listener is easy with Hibiscus! All you have to do is annotate your bean class with the @EventListener annotation (which also allows it to be "scanned" by Spring) and annotate each event handler method with an @OnEvent annotation.

@EventListener
public class MyEventListener
{
  @OnEvent(EventTypeEnum.POST_COMMIT_INSERT)
  public void afterInsert(PostInsertEvent e)
  {
    // Do something
  }
}

This will allow your afterInsert() method to be called whenever a "post commit insert" event happens in Hibernate. In order to have your event listeners registered, you must first "bootstrap" them.

Bootstrapping

In your Spring configuration, you will need to include a "bootstrap" bean:

<beans>
  <bean id="bootstrap" class="com.carmanconsulting.hibiscus.event.spring.EntityManagerEventListenerBootstrap">
    <constructor-arg ref="entityManagerFactory"/>
  </bean>
</beans>

This bean will search the Spring context for all @EventListener-annotated beans and register event listeners for each @OnEvent-annotated methods contained in them.

Type-Safe Events

Sometimes, you only want to handle events for certain entity types. To achieve this, all you need to do is add a parameter to your event handler method for the entity type you wish to support. Hibiscus will automatically bind the entity object to this parameter when your event handler is called. Your event handler will not be called for events with entities of a different type.

@EventListener
public class MyEventListener
{
  @OnEvent(EventTypeEnum.POST_COMMIT_INSERT)
  public void onPostInsert(PostInsertEvent e, MyEntity myEntity)
  {
    // Do something
  }
}

Only events for entities of type MyEntity will be delivered to this event listener!

Versions

Version
1.1
1.0