[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3633) Envers ignores empty discriminator classes

Mark Derricutt (JIRA) noreply at atlassian.com
Mon Dec 8 23:04:15 EST 2008


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

Mark Derricutt commented on HHH-3633:
-------------------------------------

The problem is triggered when an entity include:

    private CountryGeo countryGeo;

    @ManyToOne
    @JoinColumn(table = "postal_address", name = "country_geo_id", referencedColumnName = "geo_id", nullable = true, insertable = true, updatable = true)
    @Versioned
    public CountryGeo getCountryGeo() {
        return countryGeo;
    }

    public void setCountryGeo(CountryGeo countryGeo) {
        this.countryGeo = countryGeo;
    }

On the envers side of things, org.hibernate.envers.configuration.metadata.AuditMetadataGenerator#generateFirstPass only stores a reference to Geo in its entitiesConfigurations map, so the CountryGeo reference is not found.

As an initial experiment, I tried modifying envers to also store references to the subclasses:

Index: src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java	(revision 15671)
+++ src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java	(working copy)
@@ -41,11 +41,7 @@
 
 import org.hibernate.MappingException;
 import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.Collection;
-import org.hibernate.mapping.Join;
-import org.hibernate.mapping.PersistentClass;
-import org.hibernate.mapping.Property;
-import org.hibernate.mapping.Value;
+import org.hibernate.mapping.*;
 import org.hibernate.type.CollectionType;
 import org.hibernate.type.ManyToOneType;
 import org.hibernate.type.OneToOneType;
@@ -328,6 +324,11 @@
         EntityConfiguration entityCfg = new EntityConfiguration(auditEntityName, idMapper,
                 propertyMapper, parentEntityName);
         entitiesConfigurations.put(pc.getEntityName(), entityCfg);
+
+        Iterator subclasses = pc.getDirectSubclasses();
+        while (subclasses.hasNext()) {
+            entitiesConfigurations.put(((Subclass) subclasses.next()).getEntityName(), entityCfg);
+        }
     }

Whilst envers looked like it started up all fine, the moment I tried writing data via hibernate very odd side effects came about.


> Envers ignores empty discriminator classes
> ------------------------------------------
>
>                 Key: HHH-3633
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3633
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: envers
>    Affects Versions: 3.4
>            Reporter: Mark Derricutt
>
> 'lo
> I'm just working through updating our system to Hibernate 3.3 and the new maven based envers from trunk and am noticing that empty discriminator classes such as:
> @Entity
> @DiscriminatorValue("11004")
> @Versioned
> public class CountryGeo extends Geo {
> }
> are getting ignored by envers.  This is manifested as the error "An audited relation to a non-audited entity" thrown from ToOneRelationMetadataGenerator.

-- 
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