2 Replies Latest reply on Jun 9, 2008 7:28 AM by adamw

    Inconsistent field mappings used in joined columns

    talios

      'lo,

      I noticed some inconsistency with field column names used by envers for joined tables, I've entered this currently in JIRA as http://jira.jboss.com/jira/browse/ENVERS-15 but thought I'd comment here as well.

      Maybe the problem stems from me not using Hibernate (or envers extension) to generate my schema.

      My classes have joined annotated as:

       @ManyToOne(cascade = {CascadeType.ALL})
       @JoinColumn(name = "contact_mech_id", referencedColumnName = "contact_mech_id", nullable = false, insertable = true, updatable = true)
       public ContactMech getContactMech() {
       return contactMech;
       }
      


      so that the column name is contact_mech_id, however envers generates the mapping to be contactMech_contact_mech_id instead.

      After walking through the code and trying to work out whats going on, changing org.jboss.envers.metadata.VersionsMetadataGenerator#addToOne to use:

      Column column = (Column) property.getValue().getColumnIterator().next();
      IdMapper relMapper = new SingleIdMapper(property.getName(), column.getName());
      


      instead of the prefixed version things started to work again (which revealed some other issues, which I'll post separately).

      Obviously this is a rather hackish alteration. Ideally I'd like to keep my column names in the versions table consistent with my normal table, so I wondering if there was any particular reason for the current behaviour?



        • 1. Re: Inconsistent field mappings used in joined columns
          talios

          Interesting. I just reworked our build environment so I can use the Envers schema generator and it dished out the schema as I expected:

           create table smx3.contact_mech_versions (
           _versions_id int4 not null,
           contact_mech_id int4,
           _revision int4 not null,
           info_string varchar(255),
           _revision_type int2,
           contact_mech_type_id int4,
           primary key (_versions_id),
           unique (contact_mech_id, _revision)
           );
          


          Is the hibernate schema generator code using the same VersionsMetadataGenerator that envers uses at run-time?

          • 2. Re: Inconsistent field mappings used in joined columns
            adamw

            Hello,

            yes, it's exactly the same. Weird :)

            I'll take a look.

            --
            Adam