Search in sources :

Example 1 with NotInstrumentedException

use of org.hibernate.bytecode.spi.NotInstrumentedException in project hibernate-orm by hibernate.

the class BytecodeEnhancementMetadataPojoImpl method injectInterceptor.

@Override
public LazyAttributeLoadingInterceptor injectInterceptor(Object entity, SharedSessionContractImplementor session) {
    if (!enhancedForLazyLoading) {
        throw new NotInstrumentedException("Entity class [" + entityClass.getName() + "] is not enhanced for lazy loading");
    }
    if (!entityClass.isInstance(entity)) {
        throw new IllegalArgumentException(String.format("Passed entity instance [%s] is not of expected type [%s]", entity, getEntityName()));
    }
    final LazyAttributeLoadingInterceptor interceptor = new LazyAttributeLoadingInterceptor(getEntityName(), lazyAttributesMetadata.getLazyAttributeNames(), session);
    ((PersistentAttributeInterceptable) entity).$$_hibernate_setInterceptor(interceptor);
    return interceptor;
}
Also used : NotInstrumentedException(org.hibernate.bytecode.spi.NotInstrumentedException) LazyAttributeLoadingInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor) PersistentAttributeInterceptable(org.hibernate.engine.spi.PersistentAttributeInterceptable)

Aggregations

LazyAttributeLoadingInterceptor (org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor)1 NotInstrumentedException (org.hibernate.bytecode.spi.NotInstrumentedException)1 PersistentAttributeInterceptable (org.hibernate.engine.spi.PersistentAttributeInterceptable)1