Search code examples
javaproxy-classes

Not able to get exact class name


I am not able to get exact className

My code is :

venue.getClass.getName();

It's giving output like:

com.venue.Venue_java_assist17_

I've to get output like exact classname: com.venue.Venue


Solution

  • You can't directly get the class name, since it is a proxy. The only way to get the real class name is to strip of the suffix, e.g.:

    String cn = "com.venue.Venue_java_assist17_";
    System.out.println(cn.substring(0, cn.indexOf('_', cn.lastIndexOf('.'))));
    

    If you are using Hibernate, you could use:

    HibernateProxyHelper.getClassWithoutInitializingProxy(venue);