Code:
@Entity
@NamedQueries({
@NamedQuery(name="account.forEarnedSms", query="select tx.account FROM EarnedTransaction tx" +
" WHERE tx.account.group = :group AND tx.year = :year AND tx.quarter = :quarter " +
"AND (tx.lapsed is null OR tx.lapsed = :lapsed) AND tx.claimDate is null AND tx.claimType is null)"),
})
public class Account implements Serializable {
@Id
private String msisdn;
private Date activationDate;
private Date optInDate;
private Date optOutDate;
@Column(name="accountGroup")
private Integer group;
@Transient
private Double total;
public String getMsisdn() {
return msisdn;
}
public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}
public Date getActivationDate() {
return activationDate;
}
public void setActivationDate(Date activationDate) {
this.activationDate = activationDate;
}
public Date getOptInDate() {
return optInDate;
}
public void setOptInDate(Date optInDate) {
this.optInDate = optInDate;
}
public Date getOptOutDate() {
return optOutDate;
}
public void setOptOutDate(Date optOutDate) {
this.optOutDate = optOutDate;
}
public Integer getGroup() {
return group;
}
public void setGroup(Integer group) {
this.group = group;
}
public Double getTotal() {
return total;
}
public void setTotal(Double total) {
this.total = total;
}
}
public class EarnedTransaction extends RewardTransaction {
private static final long serialVersionUID = 3806591283616853649L;
@Enumerated(EnumType.STRING)
private ClaimType claimType;
private Date claimDate;
private String channelId;
private String agentId;
private Boolean lapsed;
public ClaimType getClaimType() {
return claimType;
}
public void setClaimType(ClaimType claimType) {
this.claimType = claimType;
}
public Date getClaimDate() {
return claimDate;
}
public void setClaimDate(Date claimDate) {
this.claimDate = claimDate;
}
public String getChannelId() {
return channelId;
}
public void setChannelId(String channelId) {
this.channelId = channelId;
}
public String getAgentId() {
return agentId;
}
public void setAgentId(String agentId) {
this.agentId = agentId;
}
public Boolean getLapsed() {
return lapsed;
}
public void setLapsed(Boolean lapsed) {
this.lapsed = lapsed;
}
Now i have to wirte a single !! query such way
The sum return from the below query has to be put in the total(Transient) of Account table
SELECT sum(tx.amount) FROM EarnedTransaction tx WHERE tx.year = :fromYear AND tx.quarter = :fromQuarter AND tx.account.msisdn = :msisdn AND (tx.lapsed is null OR tx.lapsed = :lapsed) AND tx.claimDate is null AND tx.claimType is null"
Please some one help.
Thanks in advance