Example usage for org.hibernate.proxy.pojo.javassist JavassistProxyFactory postInstantiate

List of usage examples for org.hibernate.proxy.pojo.javassist JavassistProxyFactory postInstantiate

Introduction

In this page you can find the example usage for org.hibernate.proxy.pojo.javassist JavassistProxyFactory postInstantiate.

Prototype

@Override
    public void postInstantiate(final String entityName, final Class persistentClass, final Set<Class> interfaces,
            final Method getIdentifierMethod, final Method setIdentifierMethod, CompositeType componentIdType)
            throws HibernateException 

Source Link

Usage

From source file:org.emonocot.model.BaseTest.java

License:Open Source License

/**
 * Another problem with//  w w w .ja  v  a  2 s.c o  m
 * http://build.e-monocot.org/bugzilla/show_bug.cgi?id=262 Unexpected Taxon
 * Exception in DwC Harvesting even though the taxon is expected. Comparing
 * HibernateProxies with non-proxies means you can't use o1.getClass() ==
 * o2.getClass().
 * @throws Exception if there is a problem
 */
@Test
public final void testEqualsWithHibernateProxies() throws Exception {
    b2.setIdentifier("test");
    b2.setId(1L);
    b1.setIdentifier("test");
    b1.setId(1L);
    SessionImplementor sessionImplementor = EasyMock.createMock(SessionImplementor.class);
    SessionFactoryImplementor sessionFactoryImplementor = EasyMock.createMock(SessionFactoryImplementor.class);
    EntityPersister entityPersister = EasyMock.createMock(EntityPersister.class);
    PersistenceContext persistenceContext = EasyMock.createMock(PersistenceContext.class);
    EasyMock.expect(sessionImplementor.getFactory()).andReturn(sessionFactoryImplementor).anyTimes();
    EasyMock.expect(sessionFactoryImplementor.getEntityPersister((String) EasyMock.eq("Annotation")))
            .andReturn(entityPersister).anyTimes();
    EasyMock.expect(sessionImplementor.getPersistenceContext()).andReturn(persistenceContext);
    EasyMock.expect(persistenceContext.isDefaultReadOnly()).andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(entityPersister.isMutable()).andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(sessionImplementor.isClosed()).andReturn(Boolean.FALSE).anyTimes();
    EasyMock.expect(sessionImplementor.isOpen()).andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(sessionImplementor.isConnected()).andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(sessionImplementor.immediateLoad(EasyMock.eq("Annotation"), EasyMock.eq(1L))).andReturn(b2)
            .anyTimes();

    EasyMock.replay(sessionImplementor, sessionFactoryImplementor, entityPersister, persistenceContext);

    JavassistProxyFactory javassistProxyFactory = new JavassistProxyFactory();
    Set interfaces = new HashSet();
    interfaces.add(HibernateProxy.class);
    interfaces.add(Serializable.class);
    interfaces.add(Identifiable.class);
    interfaces.add(SecuredObject.class);

    javassistProxyFactory.postInstantiate("Annotation", Annotation.class, interfaces,
            Annotation.class.getDeclaredMethod("getId"),
            Annotation.class.getDeclaredMethod("setId", Long.class), null);

    b3 = javassistProxyFactory.getProxy(1L, sessionImplementor);

    EasyMock.verify(sessionImplementor, sessionFactoryImplementor, entityPersister, persistenceContext);
    assertTrue("Equals should return true", b1.equals(b3));
}