I have a JSF converter that I use for a SelectItem list containing several different types of entities. In the method, getAsString()I create a string as the class name, marked with ":" and identifier.
MySuperClass superClass = (MySuperClass)value;
if(superClass != null) {
return String.valueOf(superClass.getClass().getName()+":"+superClass.getId());
}
This allows me to load the correct object getAsObject()on the way back from the user interface by doing the following:
String className = value.substring(0, value.indexOf(":"));
long id = Long.parseLong(value.substring(value.indexOf(":")+1));
Class<T> entitySuperClass = (Class<T>) Class.forName(className);
MySuperClass superClass = (MySuperClass)getEntityManager().find(entitySuperClass, id);
My problem is that my object in getAsString()is a proxy server. So instead of getting com.company.MyEntitywhen I do getClass (). GetName () I receive com.company.MyEntity_$$_javassist_48, and then it fails on find().
Is there a way (other than string manipulation) to get a specific class name (e.g. com.company.MyEntity)?
Thanks.