0

I'm working a lot with java reflection, and i'm using a map to store metadata from each bean in the application. I use the className as a key, so, the problem is that when a ask for the className of a bean).

bean.getClass().getName()

I can get two different results, depending if the bean is lazy loaded or not (some relations are lazy, some aren't, but i want to work with both of them.

For example, the Class:

package com.factorit.beans;<br>
public class Task  implements java.io.Serializable {

If called in a normal loaded object, it returns:

com.factorit.beans.Task

but if called in a lazy initialized object, it returns

com.factorit.beans.Task$$EnhancerByCGLIB$$f9d61939

I was wondering if there is a way to get this, or if I have to parse the String.

Thank you so much for any help or advice.

EDIT: Just to add some info: My Lazy annotattions look like this:

@javax.persistence.ManyToOne(fetch = javax.persistence.FetchType.LAZY)

and I'm using Struts 2.1.8.1, Hibernate 3 and Spring 2.5.6.

Germán
  • 328
  • 6
  • 15
  • 2
    Will unwrapping CGLIB proxy [as described here](http://stackoverflow.com/a/8121671/605744) work for you? – Tomasz Nurkiewicz Oct 22 '12 at 21:53
  • Hi @TomaszNurkiewicz. I tried what is on the post you pointed, but all the options give me false as result. * AopUtils.isAopProxy(item) * AopUtils.isCglibProxy(item) * AopUtils.isJdkDynamicProxy(item) – Germán Oct 22 '12 at 22:23

1 Answers1

1

If was debuging struts2-json-plugin 2.1.8.1, and in the method JSONWritter.bean(Object object) I found that they are using this line

if (clazz.getName().indexOf("$$EnhancerByCGLIB$$") > -1) {

so, if even them have to parse the string, I suppouse there is no better way. Thank you @TomaszNurkiewicz for your help.

Germán
  • 328
  • 6
  • 15