Search in sources :

Example 1 with ProxyConfiguration

use of org.hibernate.proxy.ProxyConfiguration in project hibernate-orm by hibernate.

the class ByteBuddyProxyFactory method getProxy.

@Override
public HibernateProxy getProxy(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
    final ByteBuddyInterceptor interceptor = new ByteBuddyInterceptor(entityName, persistentClass, interfaces, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session, overridesEquals);
    try {
        final HibernateProxy proxy = (HibernateProxy) proxyClass.newInstance();
        ((ProxyConfiguration) proxy).$$_hibernate_set_interceptor(interceptor);
        return proxy;
    } catch (Throwable t) {
        LOG.error(LOG.bytecodeEnhancementFailed(entityName), t);
        throw new HibernateException(LOG.bytecodeEnhancementFailed(entityName), t);
    }
}
Also used : ProxyConfiguration(org.hibernate.proxy.ProxyConfiguration) HibernateException(org.hibernate.HibernateException) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 2 with ProxyConfiguration

use of org.hibernate.proxy.ProxyConfiguration in project hibernate-orm by hibernate.

the class ByteBuddyProxyFactory method deserializeProxy.

public static HibernateProxy deserializeProxy(SerializableProxy serializableProxy) {
    final ByteBuddyInterceptor interceptor = new ByteBuddyInterceptor(serializableProxy.getEntityName(), serializableProxy.getPersistentClass(), serializableProxy.getInterfaces(), serializableProxy.getId(), resolveIdGetterMethod(serializableProxy), resolveIdSetterMethod(serializableProxy), serializableProxy.getComponentIdType(), null, ReflectHelper.overridesEquals(serializableProxy.getPersistentClass()));
    // note: interface is assumed to already contain HibernateProxy.class
    try {
        final Class proxyClass = buildProxy(serializableProxy.getPersistentClass(), serializableProxy.getInterfaces());
        final HibernateProxy proxy = (HibernateProxy) proxyClass.newInstance();
        ((ProxyConfiguration) proxy).$$_hibernate_set_interceptor(interceptor);
        return proxy;
    } catch (Throwable t) {
        final String message = LOG.bytecodeEnhancementFailed(serializableProxy.getEntityName());
        LOG.error(message, t);
        throw new HibernateException(message, t);
    }
}
Also used : ProxyConfiguration(org.hibernate.proxy.ProxyConfiguration) HibernateException(org.hibernate.HibernateException) HibernateProxy(org.hibernate.proxy.HibernateProxy)

Example 3 with ProxyConfiguration

use of org.hibernate.proxy.ProxyConfiguration in project hibernate-orm by hibernate.

the class BasicProxyFactoryImpl method getProxy.

public Object getProxy() {
    try {
        final ProxyConfiguration proxy = (ProxyConfiguration) proxyClass.newInstance();
        proxy.$$_hibernate_set_interceptor(new PassThroughInterceptor(proxy, proxyClass.getName()));
        return proxy;
    } catch (Throwable t) {
        throw new HibernateException("Unable to instantiate proxy instance");
    }
}
Also used : ProxyConfiguration(org.hibernate.proxy.ProxyConfiguration) HibernateException(org.hibernate.HibernateException)

Aggregations

HibernateException (org.hibernate.HibernateException)3 ProxyConfiguration (org.hibernate.proxy.ProxyConfiguration)3 HibernateProxy (org.hibernate.proxy.HibernateProxy)2