1 Reply Latest reply on Sep 4, 2009 4:36 PM by Francisco Jose Peredo Noguez

    SEAM HQL Question

    Ypatios Asmanidis Newbie

      I have three entities


      Customer entity




      package panda.entities;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.persistence.Column;
      import javax.persistence.DiscriminatorValue;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.OneToMany;
      import javax.persistence.Table;
      import javax.persistence.Transient;
      import javax.persistence.UniqueConstraint;
      
      import org.jboss.seam.annotations.Name;
      
      
      @Entity
      @DiscriminatorValue("customer")
      @Name("customer")
      public class Customer extends Person implements Serializable {
      
           /**
            * 
            */
           private static final long serialVersionUID = -22078731036388186L;     
           
           private List<Invoice> invoices;
           private List<CustomerTransaction> customerTransactions;
           private String brandname;
           private String statusImage;
           
           public Customer() {}
           
           
           @Column(unique=true)
           public String getBrandname() {
                return brandname;
           }
           public void setBrandname(String brandname) {
                this.brandname = brandname;
           }
           
           @OneToMany
           public List<Invoice> getInvoices() {
                return invoices;
           }
           public void setInvoices(List<Invoice> invoices) {
                this.invoices = invoices;
           }
           
           @OneToMany
           public List<CustomerTransaction> getCustomerTransactions() {
                return customerTransactions;
           }
           public void setCustomerTransactions(
                     List<CustomerTransaction> customerTransactions) {
                this.customerTransactions = customerTransactions;
           }
           
           @Transient
           public void addInvoice(Invoice inv) {
                
                if(this.invoices==null) {
                     invoices=new ArrayList<Invoice>();
                }
                
                invoices.add(inv);
                
                
           }
           
           @Transient
           public void addTransaction(CustomerTransaction tran) {
                if(this.customerTransactions==null) {
                     customerTransactions=new ArrayList<CustomerTransaction>();
                }
                
                customerTransactions.add(tran);
                
           }
      
           @Override
           public String toString() {
                // TODO Auto-generated method stub
                return this.brandname;
           }
      
           @Transient
           public String getStatusImage() {
                return statusImage;
           }
      
      
           public void setStatusImage(String statusImage) {
                this.statusImage = statusImage;
           }
           
           
      }
      



      Transaction entity




      package panda.entities;
      
      import java.io.Serializable;
      import java.util.Date;
      
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      
      
      @Entity
      public class CustomerTransaction implements Serializable{
      
           /**
            * 
            */
           private static final long serialVersionUID = -7177554785463001529L;
           
           private long id;
           private double amount;
           private String description;
           private Date date;
           
           @Id @GeneratedValue
           public long getId() {
                return id;
           }
           public void setId(long id) {
                this.id = id;
           }
           public double getAmount() {
                return amount;
           }
           public void setAmount(double amount) {
                this.amount = amount;
           }
           public String getDescription() {
                return description;
           }
           public void setDescription(String description) {
                this.description = description;
           }
           public Date getDate() {
                return date;
           }
           public void setDate(Date date) {
                this.date = date;
           }
           
           
           
           
           
           
      
      }
      



      Invoice Entity




      package panda.entities;
      
      import java.io.Serializable;
      import java.util.Date;
      import java.util.List;
      
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.OneToMany;
      
      import org.hibernate.validator.NotNull;
      
      
      
      
      @Entity
      public class Invoice implements Serializable{
      
           /**
            * 
            */
           private static final long serialVersionUID = 1510168101209093640L;
           
           
      
           
           @OneToMany
           public List<InvoiceDetails> getInvoiceDetails() {
                return invoiceDetails;
           }
           public void setInvoiceDetails(List<InvoiceDetails> invoiceDetails) {
                this.invoiceDetails = invoiceDetails;
           }
           private long id;
           private Date date;
           private double amount;
           private float fpa;
           private int invoiceState=0;
          private List<InvoiceDetails> invoiceDetails;
           
           @Id @GeneratedValue
           public long getId() {
                return id;
           }
           public void setId(long id) {
                this.id = id;
           }
           public Date getDate() {
                return date;
           }
           public void setDate(Date date) {
                this.date = date;
           }
           public double getAmount() {
                return amount;
           }
           public void setAmount(double amount) {
                this.amount = amount;
           }
           public float getFpa() {
                return fpa;
           }
           public void setFpa(float fpa) {
                this.fpa = fpa;
           }
           
           @NotNull
           public int getInvoiceState() {
                return invoiceState;
           }
           public void setInvoiceState(int state) {
                this.invoiceState = state;
           }
          
      }
      


      how can I retrieve the customers that the invoice total amount is bigger than the transaction total amount?