Spring JPA: I must be doing something wrong because I do not manage to audit bi direc...
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 25 Jul 2016 19:24:09 +0000 (21:24 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Mon, 25 Jul 2016 19:24:09 +0000 (21:24 +0200)
SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/Ad.java

index 73672a2..dbfb184 100644 (file)
@@ -23,6 +23,8 @@ import javax.validation.constraints.Max;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 
+import org.hibernate.envers.AuditJoinTable;
+import org.hibernate.envers.AuditMappedBy;
 import org.hibernate.envers.Audited;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -32,7 +34,7 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
 import de.spring.example.persistence.converters.OffsetDateTimeAttributeConverter;
 
 @Entity
-@Audited(withModifiedFlag=true)
+//@Audited(withModifiedFlag=true)
 @Table(name="AD", schema="mybatis_example")
 @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="jsonId")
 // 1. Named query is JPL. It is portable.
@@ -66,33 +68,42 @@ import de.spring.example.persistence.converters.OffsetDateTimeAttributeConverter
 //)
 public class Ad implements Serializable {
 
+       @Audited(withModifiedFlag=true)
        @Id
        @GeneratedValue(strategy=GenerationType.IDENTITY)
        @Column(name="ID", updatable=false, nullable=false)
        private Long id;
        
+       // NO WAY OF AUDITING THIS COLUMN :(. AM I MESSING SOMETHING UP WITH JPA AND RELATIONS BETWEEN TABLES?
+       @AuditJoinTable(name="AD_DESCRIPTION_AUDITED")
+       @AuditMappedBy(mappedBy="ad", positionMappedBy="id")
        @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
        @JoinColumn(name = "AD_ID", nullable = false)
        private Set<AdDescription> adDescriptions;
        
+       @Audited(withModifiedFlag=true)
        @Max(60)
        @Column(name="COMPANY_ID")
        private Long companyId;
        
+       @Audited(withModifiedFlag=true)
        @Max(40)
        @Column(name="COMPANY_CATEG_ID")
        private Long companyCategId;
        
+       @Audited(withModifiedFlag=true)
        @Size(min=2, max=255)
        @Column(name="AD_MOBILE_IMAGE")
        private String adMobileImage;
 
+       @Audited(withModifiedFlag=true)
        @NotNull
        @Convert(converter=OffsetDateTimeAttributeConverter.class)
        @Column(name="CREATED_AT", nullable=false)
        @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ssZ")
        private OffsetDateTime createdAt;
        
+       @Audited(withModifiedFlag=true)
        @NotNull
        @Convert(converter=OffsetDateTimeAttributeConverter.class)
        @Column(name="UPDATED_AT", nullable = false)