[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4112?page=c...
]
David Green commented on HHH-4112:
----------------------------------
Thanks for the response. I agree that there are workarounds.
_class_ annotations should not be propagated by the Java runtime unless they're
@Inherited, but the same does not apply for overridden methods. You're also correct
in that this is the correct behaviour for the Java runtime, however the difference here
is that the developer did not extend these JPA classes in their code nor did the developer
override any of these class methods in their code. Thus the developer's intention is
that these classes should retain their annotations: the codebase should rightly expect to
be introspecting the classes as they're declared.
The bug here is that introspection on these classes behaves differently when these classes
are bytecode-enhanced by Hibernate. A simple Hibernate runtime configuration setting can
cause the application to fail in unexpected ways.
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira