[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4112) HibernateProxy enhanced POJOs lose method annotations

David Green (JIRA) noreply at atlassian.com
Fri Aug 28 16:53:15 EDT 2009


HibernateProxy enhanced POJOs lose method annotations
-----------------------------------------------------

                 Key: HHH-4112
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4112
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.0.ga
            Reporter: David Green


Using FetchType.LAZY on an association can result in POJO entities being enhanced via JavassistProxyFactory or CGLIBProxyFactory.  The resulting class overrides all declared accessors and mutators (get/set methods) in the original POJO.  Those overridden methods lose any annotations that were specified on the original POJO.

The result is that unsuspecting code looking for annotations on POJO accessors won't find any annotations.

For example, if I have an @Entity POJO called Resident, the following JUnit test will fail for both CGLIBProxyFactory and JavassistProxyFactory:

{code:Java}
	public void testCGLibProxy() throws HibernateException, SecurityException, NoSuchMethodException {
		doTest(new CGLIBProxyFactory());
	}

	public void testJavassistProxy() throws HibernateException, SecurityException, NoSuchMethodException {
		doTest(new JavassistProxyFactory());
	}

	private void doTest(ProxyFactory proxyFactory) throws NoSuchMethodException {
		HashSet proxyInterfaces = new HashSet();
		proxyInterfaces.add( HibernateProxy.class );
		proxyFactory.postInstantiate("Resident", Resident.class, proxyInterfaces, Resident.class.getDeclaredMethod("getId"), Resident.class.getDeclaredMethod("setId",Long.class), null);
		HibernateProxy hibernateProxy = proxyFactory.getProxy(resident.getId(), session);
		assertTrue(hibernateProxy instanceof Resident);
		
		System.out.println("Hibernate proxy name: "+hibernateProxy.getClass().getName());
		
		assertNotNull(Resident.class.getDeclaredMethod("getMaritalStatus").getAnnotation(Required.class));
		assertNotNull(hibernateProxy.getClass().getDeclaredMethod("getMaritalStatus").getAnnotation(Required.class));
	}
{code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list