9 Replies Latest reply on Aug 25, 2008 5:54 AM by Sebastian Komander

    Fix for: ENVERS-39 - Add an @Unversioned annotation

    Sebastian Komander Newbie

      Hi together,

      I have made a fix for this issue cause I always need this Feature.

      Changes:

      - Added an @Unversioned-Annotation in org.jboss.envers
      - Added a List of unversioned Properties to the org.jboss.envers.metadata.data.PersistentClassVersioningData
      - Changed org.jboss.envers.metadata.AnnotationsMetadataReader to read the @Unversioned-Annotation
      - Change org.jboss.envers.metadata.VersionsMetadataGenerator to only generate Properties to the xy_versioned-Entity if they aren't
      declared as unversioned.

      Here's the sample-class from the demo:

      package org.jboss.envers.demo;
      
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      
      import org.jboss.envers.Unversioned;
      import org.jboss.envers.Versioned;
      
      @Entity
      @Versioned
      public class Address {
       @Id
       @GeneratedValue
       private int id;
      
       private String streetName;
      
       private Integer houseNumber;
      
       @Unversioned
       private Integer flatNumber;
      
       public int getId() {
       return id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       public String getStreetName() {
       return streetName;
       }
      
       public void setStreetName(String streetName) {
       this.streetName = streetName;
       }
      
       public Integer getHouseNumber() {
       return houseNumber;
       }
      
       public void setHouseNumber(Integer houseNumber) {
       this.houseNumber = houseNumber;
       }
      
       public Integer getFlatNumber() {
       return flatNumber;
       }
      
       public void setFlatNumber(Integer flatNumber) {
       this.flatNumber = flatNumber;
       }
      
       public boolean equals(Object o) {
       if (this == o)
       return true;
       if (!(o instanceof Address))
       return false;
      
       Address address = (Address) o;
      
       if (id != address.id)
       return false;
       if (flatNumber != null ? !flatNumber.equals(address.flatNumber)
       : address.flatNumber != null)
       return false;
       if (houseNumber != null ? !houseNumber.equals(address.houseNumber)
       : address.houseNumber != null)
       return false;
       if (streetName != null ? !streetName.equals(address.streetName)
       : address.streetName != null)
       return false;
      
       return true;
       }
      
       public int hashCode() {
       int result;
       result = id;
       result = 31 * result + (streetName != null ? streetName.hashCode() : 0);
       result = 31 * result
       + (houseNumber != null ? houseNumber.hashCode() : 0);
       result = 31 * result + (flatNumber != null ? flatNumber.hashCode() : 0);
       return result;
       }
      }
      
      


      Here's my test-code:

       Map<String, String> configurationOverrides = new HashMap<String, String>();
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("ConsolePU", configurationOverrides);
       EntityManager entityManager = emf.createEntityManager();
      
       Address addy = new Address();
       addy.setFlatNumber(1);
       addy.setHouseNumber(1);
       addy.setStreetName("straße 1");
      
       entityManager.getTransaction().begin();
       entityManager.persist(addy);
       entityManager.getTransaction().commit();
      
       addy.setFlatNumber(2);
      
       entityManager.getTransaction().begin();
       entityManager.persist(addy);
       entityManager.getTransaction().commit();
      
       entityManager.close();
       emf.close();
      


      The resultig database-schema and content of the tables...
      Schema:
      [img]http://mitglied.lycos.de/sebgehacked/dev/schema.jpg[/img]

      Values:
      [img]http://mitglied.lycos.de/sebgehacked/dev/values.jpg[/img]

      Patch Download: http://people.freenet.de/sebgehacked/envers/fix_39_unversioned_annotation.zip

      Hope it helps!

      Kind regards,

      Sebastian