[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6331) Envers @mappedSupperclass bad behaviour

Lukasz Antoniak (JIRA) noreply at atlassian.com
Mon Jun 27 17:59:23 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6331?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=42727#action_42727 ] 

Lukasz Antoniak commented on HHH-6331:
--------------------------------------

Possible (ugly) workaround:
Mark class {{B}} with {{@Audited}} annotation and all it's fields with {{@NotAudited}}.

I am afraid that if we searched for {{@Audited}} annotation in every superclass (and its properties), there would be no possibility to reject auditing of those inherited attributes in another subclass. This test case shall be also taken into consideration.

Regards,
Lukasz Antoniak

> Envers @mappedSupperclass bad behaviour
> ---------------------------------------
>
>                 Key: HHH-6331
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6331
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: envers
>    Affects Versions: 3.6.1
>         Environment: Hibernate 3.6.1.Final
> Oracle 10g
>            Reporter: Facundo Mateo
>
> Suppose you have:
> * Class A marked as @MappedSuperclass, and has field/property marked as @Audited
> * Class B extends from A, and is @Entity but doesn't have any @Audited annotation
> Envers is not auditting instances of B, when it should audit the properties marked with @Audit in the superclass.
> I have been researching at the sources , and it seems to be a bug introduced with the fix for [HHH-4646|http://opensource.atlassian.com/projects/hibernate/browse/HHH-4646]. The problem is in the class org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader :
> {code:title=org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.java|borderStyle=solid}
> private void addPropertiesFromClass(XClass clazz)  {
> 		Audited allClassAudited = clazz.getAnnotation(Audited.class);
> 		//look in the class
> 		addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties, allClassAudited);
> 		addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties, allClassAudited);
> 		
> 		if(allClassAudited != null || !auditedPropertiesHolder.isEmpty()) {
> 			XClass superclazz = clazz.getSuperclass();
> 			if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
> 				addPropertiesFromClass(superclazz);
> 			}
> 		}
> 	}
> {code}
> if you look this line 	*if(allClassAudited != null || !auditedPropertiesHolder.isEmpty())*: It only looks for @Audited annotation when the child is marked with class level @Audited or if it has some @Audited property/field, but ignores superclass annotations if it the child doesn't have any.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list