[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-4112) HibernateProxy enhanced POJOs lose method annotations
Emmanuel Bernard (JIRA)
noreply at atlassian.com
Mon Nov 30 11:57:13 EST 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4112?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Emmanuel Bernard resolved HHH-4112.
-----------------------------------
Resolution: Won't Fix
You can do Hibernate.getClass() to get the true class, or simply go to the superclass and the supermethods to find the annotations.
As most annotations are not @Inherited, I think that's the correct behavior.
> 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