Search in sources :

Example 1 with Listener

use of org.hibernate.jpa.event.spi.jpa.Listener in project hibernate-orm by hibernate.

the class ListenerFactoryStandardImpl method buildListener.

@Override
@SuppressWarnings("unchecked")
public <T> Listener<T> buildListener(Class<T> listenerClass) {
    ListenerImpl listenerImpl = listenerInstances.get(listenerClass);
    if (listenerImpl == null) {
        try {
            T listenerInstance = listenerClass.newInstance();
            listenerImpl = new ListenerImpl(listenerInstance);
        } catch (Exception e) {
            throw new PersistenceException("Unable to create instance of " + listenerClass.getName() + " as a JPA callback listener", e);
        }
        ListenerImpl existing = listenerInstances.putIfAbsent(listenerClass, listenerImpl);
        if (existing != null) {
            listenerImpl = existing;
        }
    }
    return (Listener<T>) listenerImpl;
}
Also used : Listener(org.hibernate.jpa.event.spi.jpa.Listener) PersistenceException(javax.persistence.PersistenceException) PersistenceException(javax.persistence.PersistenceException)

Aggregations

PersistenceException (javax.persistence.PersistenceException)1 Listener (org.hibernate.jpa.event.spi.jpa.Listener)1