Java Code Examples for org.hibernate.event.spi.PostLoadEvent#getEntity()
The following examples show how to use
org.hibernate.event.spi.PostLoadEvent#getEntity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuditLogPostLoadEventListener.java From high-performance-java-persistence with Apache License 2.0 | 6 votes |
@Override public void onPostLoad(PostLoadEvent event) { final Object entity = event.getEntity(); final EntityPersister entityPersister = event.getPersister(); if (entity instanceof Auditable) { Auditable auditable = (Auditable) entity; event.getSession().persist( new LoadEventLogEntry() .setCreatedBy(LoggedUser.get()) .setEntityName(entityPersister.getEntityName()) .setEntityId(String.valueOf(auditable.getId())) ); } }
Example 2
Source File: DefaultPostLoadEventListener.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void onPostLoad(PostLoadEvent event) { final Object entity = event.getEntity(); callbackRegistry.postLoad( entity ); final EntityEntry entry = event.getSession().getPersistenceContext().getEntry( entity ); if ( entry == null ) { throw new AssertionFailure( "possible non-threadsafe access to the session" ); } final LockMode lockMode = entry.getLockMode(); if ( LockMode.PESSIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) { final EntityPersister persister = entry.getPersister(); final Object nextVersion = persister.forceVersionIncrement( entry.getId(), entry.getVersion(), event.getSession() ); entry.forceLocked( entity, nextVersion ); } else if ( LockMode.OPTIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) { final EntityIncrementVersionProcess incrementVersion = new EntityIncrementVersionProcess( entity, entry ); event.getSession().getActionQueue().registerProcess( incrementVersion ); } else if ( LockMode.OPTIMISTIC.equals( lockMode ) ) { final EntityVerifyVersionProcess verifyVersion = new EntityVerifyVersionProcess( entity, entry ); event.getSession().getActionQueue().registerProcess( verifyVersion ); } if ( event.getPersister().implementsLifecycle() ) { //log.debug( "calling onLoad()" ); ( (Lifecycle) event.getEntity() ).onLoad( event.getSession(), event.getId() ); } }
Example 3
Source File: PostLoadAuditListener.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onPostLoad( PostLoadEvent postLoadEvent ) { Object entity = postLoadEvent.getEntity(); getAuditable( entity, "read" ).ifPresent( auditable -> auditManager.send( Audit.builder() .auditType( getAuditType() ) .auditScope( auditable.scope() ) .createdAt( LocalDateTime.now() ) .createdBy( getCreatedBy() ) .object( entity ) .auditableEntity( new AuditableEntity( entity ) ) .build() ) ); }
Example 4
Source File: ClosureEventTriggeringInterceptor.java From gorm-hibernate5 with Apache License 2.0 | 4 votes |
public void onPostLoad(PostLoadEvent hibernateEvent) { Object entity = hibernateEvent.getEntity(); activateDirtyChecking(entity); publishEvent(hibernateEvent, new org.grails.datastore.mapping.engine.event.PostLoadEvent( this.datastore, entity)); }