Date プロパティを ejb3 エンティティの文字列プロパティとして最適に保持するにはどうすればよいですか?
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entities;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author nikola
*/
@Entity
@Table(name = "CHART")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Chart.findAll", query = "SELECT c FROM Chart c"),
@NamedQuery(name = "Chart.findById", query = "SELECT c FROM Chart c WHERE c.id = :id"),
@NamedQuery(name = "Chart.findByAmount", query = "SELECT c FROM Chart c WHERE c.amount = :amount"),
@NamedQuery(name = "Chart.findByAmountdue", query = "SELECT c FROM Chart c WHERE c.amountdue = :amountdue")
})
public class Chart implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.TABLE)
private Integer id;
// @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
@Column(name = "AMOUNT")
private Double amount;
@Column(name = "AMOUNTDUE")
private Double amountdue;
@Column(name = "date")
private String dateofbirthString;
@javax.persistence.Transient
private Date dateofbirth;
public Chart() {
}
public Chart(Double amount, Double amountdue) {
this.amount = amount;
this.amountdue = amountdue;
this.dateofbirth = new Date();
}
public Chart(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public Double getAmountdue() {
return amountdue;
}
public void setAmountdue(Double amountdue) {
this.amountdue = amountdue;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Chart)) {
return false;
}
Chart other = (Chart) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entities.Chart[ id=" + id + " ]";
}
public Date getDateofbirth() {
return dateofbirth;
}
public void setDateofbirth(Date dateofbirth) {
this.dateofbirth = dateofbirth;
}
@PrePersist
@PreUpdate
public void convertDateToString() {
dateofbirthString = String.valueOf(dateofbirth);
}
}
エンティティはタペストリー アプリケーションで日付で並べ替え可能である必要があり、ejb セッションでは一部の計算にも日付を使用する必要がありますか?