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

Hernán Chanfreau (JIRA) noreply at atlassian.com
Sun Jul 10 11:44:16 EDT 2011


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

Hernán Chanfreau commented on HHH-6331:
---------------------------------------

Hi!
If this behavior is added, what happens if you want to audit the mappedSuperclass fields and only a part of its hierarchy? The whole hierarchy would be audited by force.
I think you should audit your subclasses explicitly. 
Think about entity annotation... you don´t make a subclass an entity by marking only the superclass with @Entity...

Regards. Hernán.

> 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.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list