I am running a function that loops through the declared fields, finds the difference between 2 instances of an object and outputs it (for audit trails). However, if I use an object loading from the hibernate session, I.E:
HazardSubmission hs = (HazardSubmission)s.load(HazardSubmission.class, id);
The declared fields of that object come out at: default_interceptor,handler,_filter,methods where if I load an object of the same type without using session.load it finds the ACTUAL declared fields fine. If I run a getClass().toString() on this hs object, it returns:
class nz.co.g.hs.stripes.model.HazardSubmission_$$_javassist_1
Where as far as I can tell javaasssist_1 is the problem, for some reason it’s not finding the actual class.
Any idea what I can do?
session.load(HazardSubmission.class, 1)will first check if the instance of the typeHazardSubmission.classwith the ID 1 can be found in the current session . If yes , that instance is returned . Otherwise , a proxy will be returned.Proxies are created dynamically by sub-classing
HazardSubmission.class.They are notHazardSubmission.classand that ‘s whygetDeclaredFields()on the returned instance are not the actualFieldof theHazardSubmission.classTo get the actual
Classfrom the generated proxy instance , you can use Hibernate.getClass()