@Override public Class<?> getPersistentClass(final Object object) { if (object == null) { return null; } try { final Field field = InvocationUtil.getField(object.getClass(), "handler"); if (field != null) { final JavassistLazyInitializer handler = InvocationUtil.getValue(object, field, AccessType.FIELD, false); return handler.getPersistentClass(); } } catch (final InvocationException e) { log.warn("Cannot run invocation for {}", object, e); } return object.getClass(); }
@Override public Optional<ObjectAccessProxy<T>> createAccessor(T entity) { if (entity instanceof HibernateProxy) { LazyInitializer lazyInitializer = ((HibernateProxy) entity).getHibernateLazyInitializer(); return fromLazyInitializer(lazyInitializer); } if (entity instanceof JavassistLazyInitializer){ JavassistLazyInitializer proxy = (JavassistLazyInitializer) entity; return fromLazyInitializer(proxy); } return Optional.empty(); }
/** * Default constructor. */ public HibernateEntityHandler() { super(); this.handler = PowerMockito.mock(JavassistLazyInitializer.class); PowerMockito.when(this.handler.getPersistentClass()).thenReturn(Integer.class); }