-
1. Re: Cannot audit subclass of non-audited "JOINED" superclass
adamw Jun 27, 2013 12:00 PM (in response to tlerma909)You would have to get the superclass audited somehow. Currently there's no other way to specify such metadata except for annotations.
Adam
-
2. Re: Cannot audit subclass of non-audited "JOINED" superclass
tlerma909 Jun 27, 2013 1:20 PM (in response to adamw)Thanks for the feedback Adam, I discovered that you were right and found that in order to accomplish this I needed to do some work to inject those annotations into the parent class at run-time. I'm using Broadleaf, which provides some class transforming interfaces where I was able to do the below, which adds class level parameter "@Audited" at run-time to the parent class:
ClassPool classPool = ClassPool.getDefault();
CtClass clazz = classPool.makeClass(new ByteArrayInputStream(
classfileBuffer), false);
clazz.defrost();
ClassFile classFile = clazz.getClassFile();
ConstPool constPool = classFile.getConstPool();
classFile.getAttributes().get(1);
AnnotationsAttribute attr = (AnnotationsAttribute) classFile.getAttributes().get(1);
Annotation auditAnnotation = new Annotation("org.hibernate.envers.Audited", constPool);
attr.addAnnotation(auditAnnotation);
classFile.addAttribute(attr);
classPool.importPackage("org.hibernate.envers.RelationTargetAuditMode");
return clazz.toBytecode();
Then broadleaf provided some other transformers that basically copy annotations from one template class to a class that is in a lib(jar) file, which I was able to use to control the field level annotations for auditing the parent super-class that is stored away in the jar file. This all happens during run-time initialization, and is currently working. Not the most straight-forward way but it works.