Loading javassist-ed hibernation object

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.

+5
3

superClass.getClass() org.hibernate.proxy.HibernateProxyHelper.getClassWithoutInitializingProxy(superClass).

+9

Hibernate.getClass() HibernateProxyHelper! HibernateProxyHelper , , ,

@Table(name = SuperClass.TABLE_NAME)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = SuperClass.TABLE_DISCRIMINATOR, discriminatorType = DiscriminatorType.STRING)

@DiscriminatorValue(value = EntityClass.TABLE_DISCRIMINATOR)

.

Hibernate.getClass(...) .

+6

(AbstractEntity < - ConcreteEntity < - ConcreteEntityProxy) :

// This should fail - trying to create an abstract class
HibernateProxyHelper.getClassWithoutInitializingProxy(superClass).newInstance()

:

protected <T> T deproxy(T maybeProxy) {
    if (maybeProxy instanceof HibernateProxy) {
        return (T) ((HibernateProxy) maybeProxy).getHibernateLazyInitializer().getImplementation();
    }
    return maybeProxy;
}
+3

All Articles