public class MyLoadListener implements LoadEventListener{ public void setSpringManagedProperty(String springManagedProperty){ this.springManagedProperty = springManagedProperty; } private String springManagedProperty; @Override public void onLoad(LoadEvent event, LoadType loadType) throws HibernateException{ if(MyEntity.class.getName().equals(event.getEntityClassName())){ MyEntity entity = (MyEntity) event.getInstanceToLoad(); entity.setMyCustomProperty(springManagedProperty); } } }
@Override public void onLoad(LoadEvent event, LoadType loadType) throws HibernateException { if ( IMMEDIATE_LOAD == loadType ) { String msg = loadType + ":" + event.getEntityClassName() + "#" + event.getEntityId(); throw new RuntimeException( msg ); } } }
public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException { if ( !Principal.isAuthorized( event.getEntityClassName(), event.getEntityId() ) ) { throw new SecurityException( "Unauthorized access" ); } } }
protected EntityPersister getPersister( final LoadEvent event ) { if ( event.getInstanceToLoad() != null ) { //the load() which takes an entity does not pass an entityName event.setEntityClassName( event.getInstanceToLoad().getClass().getName() ); return event.getSession().getEntityPersister( null, event.getInstanceToLoad() ); } else { return event.getSession().getFactory().getEntityPersister( event.getEntityClassName() ); } }
/** * Handle the given load event. * * @param event The load event to be handled. * * @throws HibernateException */ public void onLoad( final LoadEvent event, final LoadEventListener.LoadType loadType) throws HibernateException { final EntityPersister persister = getPersister( event ); if ( persister == null ) { throw new HibernateException( "Unable to locate persister: " + event.getEntityClassName() ); } final Class idClass = persister.getIdentifierType().getReturnedClass(); if ( idClass != null && !idClass.isInstance( event.getEntityId() ) && !DelayedPostInsertIdentifier.class.isInstance( event.getEntityId() ) ) { checkIdClass( persister, event, loadType, idClass ); } doOnLoad( persister, event, loadType ); }
/** * Performs the process of loading an entity from the configured * underlying datasource. * * @param event The load event * @param persister The persister for the entity being requested for load * * @return The object loaded from the datasource, or null if not found. */ protected Object loadFromDatasource( final LoadEvent event, final EntityPersister persister) { Object entity = persister.load( event.getEntityId(), event.getInstanceToLoad(), event.getLockOptions(), event.getSession() ); if ( event.isAssociationFetch() && event.getSession().getFactory().getStatistics().isStatisticsEnabled() ) { event.getSession().getFactory().getStatistics().fetchEntity( event.getEntityClassName() ); } return entity; }
.getFactory() .getEntityNotFoundDelegate() .handleEntityNotFound( event.getEntityClassName(), event.getEntityId() ); throw new NonUniqueObjectException( event.getEntityId(), event.getEntityClassName() );
@Override public void onLoad(LoadEvent event, LoadType loadType) { if ( Location.class.getName().equals( event.getEntityClassName() ) ) { locationLoadEvents.incrementAndGet(); } } }
protected EntityTypeDescriptor getDescriptor(final LoadEvent event ) { if ( event.getInstanceToLoad() != null ) { //the load() which takes an entity does not pass an entityName event.setEntityClassName( event.getInstanceToLoad().getClass().getName() ); return event.getSession().getEntityDescriptor( null, event.getInstanceToLoad() ); } else { return event.getSession().getFactory().getMetamodel().getEntityDescriptor( event.getEntityClassName() ); } }
/** * Handle the given load event. * * @param event The load event to be handled. */ public void onLoad( final LoadEvent event, final LoadEventListener.LoadType loadType) { final EntityTypeDescriptor entityDescriptor = getDescriptor( event ); if ( entityDescriptor == null ) { throw new HibernateException( "Unable to locate entityDescriptor: " + event.getEntityClassName() ); } final Class idClass = entityDescriptor.getHierarchy().getIdentifierDescriptor().getJavaType(); if ( idClass != null && !idClass.isInstance( event.getEntityId() ) && !DelayedPostInsertIdentifier.class.isInstance( event.getEntityId() ) ) { checkIdClass( entityDescriptor, event, loadType, idClass ); } doOnLoad( entityDescriptor, event, loadType ); }
protected Object loadFromDatasource( final LoadEvent event, final EntityPersister persister, final EntityKey keyToLoad, final LoadEventListener.LoadType options) { final SessionImplementor source = event.getSession(); Object entity = persister.load( event.getEntityId(), event.getInstanceToLoad(), event.getLockMode(), source ); if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) { source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() ); } return entity; }
/** * Performs the process of loading an entity from the configured * underlying datasource. * * @param event The load event * @param entityDescriptor The entityDescriptor for the entity being requested for load * * @return The object loaded from the datasource, or null if not found. */ protected Object loadFromDatasource( final LoadEvent event, final EntityTypeDescriptor entityDescriptor) { Object entity = entityDescriptor.getSingleIdLoader() .load( event.getEntityId(), event.getLockOptions(), event.getSession() ); if ( event.isAssociationFetch() && event.getSession().getFactory().getStatistics().isStatisticsEnabled() ) { event.getSession().getFactory().getStatistics().fetchEntity( event.getEntityClassName() ); } return entity; }
/** * Performs the process of loading an entity from the configured * underlying datasource. * * @param event The load event * @param persister The persister for the entity being requested for load * @param keyToLoad The EntityKey representing the entity to be loaded. * @param options The load options. * @return The object loaded from the datasource, or null if not found. */ protected Object loadFromDatasource( final LoadEvent event, final EntityPersister persister, final EntityKey keyToLoad, final LoadEventListener.LoadType options) { final SessionImplementor source = event.getSession(); Object entity = persister.load( event.getEntityId(), event.getInstanceToLoad(), event.getLockOptions(), source ); if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) { source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() ); } return entity; }
/** * Performs the process of loading an entity from the configured * underlying datasource. * * @param event The load event * @param persister The persister for the entity being requested for load * @param keyToLoad The EntityKey representing the entity to be loaded. * @param options The load options. * @return The object loaded from the datasource, or null if not found. */ protected Object loadFromDatasource( final LoadEvent event, final EntityPersister persister, final EntityKey keyToLoad, final LoadEventListener.LoadType options) { final SessionImplementor source = event.getSession(); Object entity = persister.load( event.getEntityId(), event.getInstanceToLoad(), event.getLockOptions(), source ); if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) { source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() ); } return entity; }
persister = source.getFactory().getEntityPersister( event.getEntityClassName() ); throw new HibernateException( "Unable to locate persister: " + event.getEntityClassName() );
event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( event.getEntityClassName(), event.getEntityId() ); throw new NonUniqueObjectException( event.getEntityId(), event.getEntityClassName() );
persister = source.getFactory().getEntityPersister( event.getEntityClassName() ); throw new HibernateException( "Unable to locate persister: " + event.getEntityClassName() );
event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( event.getEntityClassName(), event.getEntityId() ); throw new NonUniqueObjectException( event.getEntityId(), event.getEntityClassName() );
.getFactory() .getEntityNotFoundDelegate() .handleEntityNotFound( event.getEntityClassName(), event.getEntityId() ); throw new NonUniqueObjectException( event.getEntityId(), event.getEntityClassName() );