2 Replies Latest reply on Aug 4, 2009 6:18 AM by Adam Warski

    @DiscriminatorColumn + @DiscriminatorValue + AuditReader

    Muhammed Patel Newbie

      Hi there guys,

      I am having a little problem , i have the following query in my code

      AuditReader reader = AuditReaderFactory.get(session);
       AuditQuery query = reader.createQuery().forRevisionsOfEntity(FeeAllocation.class, false, true);
      
       query.add(AuditEntity.property("productId").eq(productId));
       query.add(AuditEntity.property("type").eq(PaymentType.Type.OngoingFee.getPrimaryId()));
       query.add(AuditEntity.revisionType().eq(RevisionType.ADD));
       query.addOrder(AuditEntity.revisionNumber().desc());
      
       Collection<Object[]> data = query.getResultList();
      


      but when i call the following line

      query.add(AuditEntity.property("type").eq(PaymentType.Type.OngoingFee.getPrimaryId()));


      Envers complains that the property called type does not exists.
      below are my entites.
      This is the super class

      package za.co.aforbes.fpc.db.model.client;
      
      import java.math.BigDecimal;
      import java.math.RoundingMode;
      import java.util.List;
      
      import javax.persistence.Column;
      import javax.persistence.DiscriminatorColumn;
      import javax.persistence.DiscriminatorType;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.Inheritance;
      import javax.persistence.InheritanceType;
      import javax.persistence.JoinColumn;
      import javax.persistence.OneToMany;
      import javax.persistence.OneToOne;
      import javax.persistence.Table;
      
      import org.hibernate.annotations.Cascade;
      import org.hibernate.annotations.LazyCollection;
      import org.hibernate.annotations.LazyCollectionOption;
      import org.hibernate.annotations.Where;
      import org.hibernate.envers.Audited;
      
      import za.co.aforbes.fpc.db.model.BaseModel;
      
      @Entity
      @Table(name = "FeeAllocation")
      @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
      @DiscriminatorColumn(name = "Type", discriminatorType = DiscriminatorType.STRING)
      public abstract class FeeAllocation extends BaseModel<Integer> {
      
       @Id
       @GeneratedValue(strategy = GenerationType.IDENTITY)
       @Column(name = "ID")
       @Audited
       private Integer primaryId;
      
       @Column(name = "ProductId")
       @Audited
       private String productId;
      
       @OneToOne
       @JoinColumn(name = "ProductPaymentUniqueId", nullable = false)
       private ProductTransaction productTransaction;
      
       @Column(name = "Status")
       @Audited
       private Integer status;
      
       @Column(name = "Rate")
       @Audited
       private BigDecimal rate;
      
       @Column(name = "Amount")
       @Audited
       private BigDecimal amount;
      
       @Column(name = "VAT")
       private BigDecimal vat;
      
       @OneToMany(mappedBy = "feeAllocation")
       @Cascade( {org.hibernate.annotations.CascadeType.SAVE_UPDATE,
       org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
       @LazyCollection(LazyCollectionOption.FALSE)
       @Where(clause = "type = 0")
       private List<LeadFeeParticipant> leadParticipants;
      
       @OneToMany(mappedBy = "feeAllocation")
       @Cascade( {org.hibernate.annotations.CascadeType.SAVE_UPDATE,
       org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
       @LazyCollection(LazyCollectionOption.FALSE)
       @Where(clause = "type = 1")
       private List<AdvisorFeeParticipant> advisorParticipants;
      
       @OneToMany(mappedBy = "feeAllocation")
       @Cascade( {org.hibernate.annotations.CascadeType.SAVE_UPDATE,
       org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
       @LazyCollection(LazyCollectionOption.FALSE)
       @Where(clause = "type = 2")
       private List<DepartmentFeeParticipant> departmentParticipants;
      
       /**
       * Constructs a new {@link FeeAllocation} model object.
       */
       public FeeAllocation() {}
      
       /**
       * Returns the {@link PaymentType} representation of this product transaction.
       *
       * @return the payment type.
       */
       public abstract PaymentType.Type getType();
      
       /**
       * Returns the {@link Boolean} representation if the fee allocation is the specified status.
       *
       * @param status the status
       * @return true if the fee allocation is in the specified type
       */
       public final boolean isStatus(FeeAllocationStatus.Status status) {
       return (getStatus() != null && getStatus().equals(status.getPrimaryId()));
       }
      
       public final void setStatus(FeeAllocationStatus.Status status) {
       this.status = status.getPrimaryId();
       }
      
       /**
       * Returns the {@link Boolean} representation if this fee allocation is the specified type.
       *
       * @param type criteria
       * @return true if the type
       */
       public final boolean isType(PaymentType.Type type) {
       return (getType() != null && getType().getPrimaryId().equals(type.getPrimaryId()));
       }
      
       /**
       * Returns the {@link BigDecimal} representation of the total advisor allocation in percentage
       * for this fee allocation.
       *
       * @return total advisor allocation
       */
       public final BigDecimal getTotalAdvisorAllocation() {
       BigDecimal total = new BigDecimal("0");
       for(FeeParticipant feeParticipant : getAdvisorParticipants()) {
       total = total.add(feeParticipant.getAdvisorSplit());
       }
       total = total.setScale(2, RoundingMode.HALF_EVEN);
       return total;
       }
      
       /**
       * Returns the {@link BigDecimal} representation of the total lead allocation amount for this
       * fee allocation.
       *
       * @return total lead allocation amount
       */
       public final BigDecimal getTotalLeadAmount() {
       BigDecimal total = new BigDecimal("0");
      
       // Check for null as not all allocation may have lead fee participant i.e.: ongoing fee
       // allocations.
       if(getLeadParticipants() != null) {
       for(FeeParticipant feeParticipant : getLeadParticipants()) {
       total = total.add(feeParticipant.getActualAmount());
       }
       }
       return total;
       }
      
       /**
       * Returns the {@link BigDecimal} representation of the total advisor allocation amount for this
       * fee allocation.
       *
       * @return total advisor allocation amount
       */
       public final BigDecimal getTotalAdvisorAmount() {
       BigDecimal total = new BigDecimal("0");
       for(FeeParticipant feeParticipant : getAdvisorParticipants()) {
       total = total.add(feeParticipant.getActualAmount());
       }
       return total;
       }
      
       /**
       * Returns the {@link BigDecimal} representation of the total branch allocation amount for this
       * fee allocation.
       *
       * @return total advisor allocation amount
       */
       public final BigDecimal getTotalDepartmentAmount() {
       BigDecimal total = new BigDecimal("0");
       for(FeeParticipant feeParticipant : getDepartmentParticipants()) {
       total = total.add(feeParticipant.getActualAmount());
       }
       return total;
       }
      
       /**
       * Returns the {@link BigDecimal} representation of the total amount for all fee participants.
       *
       * @return total fee amount
       */
       public final BigDecimal getTotalFeeParticipantAmount() {
       return getTotalLeadAmount().add(getTotalAdvisorAmount()).add(getTotalDepartmentAmount());
       }
      
       @Override
       public final Integer getPrimaryId() {
       return primaryId;
       }
      
       @Override
       public final void setPrimaryId(Integer primaryId) {
       this.primaryId = primaryId;
       }
      
       public final ProductTransaction getProductTransaction() {
       return productTransaction;
       }
      
       public final void setProductTransaction(ProductTransaction productTransaction) {
       this.productTransaction = productTransaction;
       }
      
       public final Integer getStatus() {
       return status;
       }
      
       public final void setStatus(Integer status) {
       this.status = status;
       }
      
       public final BigDecimal getRate() {
       return rate;
       }
      
       public final void setRate(BigDecimal rate) {
       this.rate = rate;
       }
      
       public final BigDecimal getAmount() {
       return amount;
       }
      
       public final void setAmount(BigDecimal amount) {
       this.amount = amount;
       }
      
       public final BigDecimal getVat() {
       return vat;
       }
      
       public final void setVat(BigDecimal vat) {
       this.vat = vat;
       }
      
       public final List<AdvisorFeeParticipant> getAdvisorParticipants() {
       return advisorParticipants;
       }
      
       public final void setAdvisorParticipants(List<AdvisorFeeParticipant> advisorParticipants) {
       if(advisorParticipants != null) {
       for(AdvisorFeeParticipant advisorFeeParticipant : advisorParticipants) {
       advisorFeeParticipant.setFeeAllocation(this);
       }
       }
       this.advisorParticipants = advisorParticipants;
       }
      
       public final List<DepartmentFeeParticipant> getDepartmentParticipants() {
       return departmentParticipants;
       }
      
       public final void setDepartmentParticipants(List<DepartmentFeeParticipant> departmentParticipants) {
       if(departmentParticipants != null) {
       for(DepartmentFeeParticipant departmentFeeParticipant : departmentParticipants) {
       departmentFeeParticipant.setFeeAllocation(this);
       }
       }
       this.departmentParticipants = departmentParticipants;
       }
      
       public final List<LeadFeeParticipant> getLeadParticipants() {
       return leadParticipants;
       }
      
       public final void setLeadParticipants(List<LeadFeeParticipant> leadParticipants) {
       if(departmentParticipants != null) {
       for(LeadFeeParticipant leadFeeParticipant : leadParticipants) {
       leadFeeParticipant.setFeeAllocation(this);
       }
       }
       this.leadParticipants = leadParticipants;
       }
      
       public final String getProductId() {
       return productId;
       }
      
       public final void setProductId(String productId) {
       this.productId = productId;
       }
      }
      


      and this is the sub class.
      package za.co.aforbes.fpc.db.model.client;
      
      import javax.persistence.DiscriminatorValue;
      import javax.persistence.Entity;
      
      import org.hibernate.envers.AuditTable;
      import org.hibernate.envers.Audited;
      
      import za.co.aforbes.fpc.db.model.client.PaymentType.Type;
      
      @Entity
      @DiscriminatorValue(value = "AFB")
      @Audited
      @AuditTable(value="FeeAllocationLog")
      public final class OngoingFeeAllocation extends FeeAllocation {
      
       /**
       * Constructs a new {@link OngoingFeeAllocation} model object.
       */
       public OngoingFeeAllocation() {}
      
       /*
       * (non-Javadoc)
       * @see za.co.aforbes.fpc.db.model.client.FeeAllocation#getType()
       */
       @Override
       public final Type getType() {
       return Type.OngoingFee;
       }
      }
      
      


      I know it has something to do with the @DiscriminatorColumn and the @DiscriminatorValue does any one have any idea on how to filter my results on that value.

      By the was the type value is being audited by envers i just don't know how to retrieve on it.



      Thanks again for any help :D

      Muhammed