hi here is my entity :
Code:
@Entity
@AccessType("property")
@Table(name = "stats")
@IdClass(StatsPK.class)
public class Stats implements Serializable,Comparable<Stats>{
private String statType;
private String paperName;
private Date beginDate;
private Date endDate;
private double value;
private String timePeriod;
@Id
public String getStatType() {return statType;}
public void setStatType(String statType) {this.statType = statType;}
@Id
public String getPaperName() {return paperName;}
public void setPaperName(String paperName) {this.paperName = paperName;}
@Id
public Date getBeginDate() {return beginDate;}
public void setBeginDate(Date beginDate) {this.beginDate = beginDate;}
@Id
public Date getEndDate() {return endDate;}
public void setEndDate(Date endDate) {this.endDate = endDate;}
@Column(name="value")
public double getValue() {return value;}
public void setValue(double value) {this.value = value;}
@Column(name="timePeriod")
public String getTimePeriod() {return timePeriod;}
public void setTimePeriod(String timePeriod) {this.timePeriod = timePeriod;}
@Override
public String toString() {
return this.getStatType() + " : " +this.getPaperName()+" : "+this.getBeginDate() + " : " + this.getEndDate() + " : " + this.getValue();
}
public int compareTo(Stats stats) {
return
this.getBeginDate().hashCode() - stats.getBeginDate().hashCode() +
this.getEndDate().hashCode() - stats.getEndDate().hashCode() +
this.getTimePeriod().hashCode() - stats.getTimePeriod().hashCode() +
this.getStatType().hashCode() - stats.getStatType().hashCode() ;
}
}
and the PK
Code:
@Embeddable
public class StatsPK implements Serializable{
private String statType;
private String paperName;
private Date beginDate;
private Date endDate;
@Column(name="stattype")
public String getStatType() {return statType;}
public void setStatType(String statType) {this.statType = statType;}
@Column(name="papername")
public String getPaperName() {return paperName;}
public void setPaperName(String paperName) {this.paperName = paperName;}
@Column(name="begindate")
public Date getBeginDate() {return beginDate;}
public void setBeginDate(Date beginDate) {this.beginDate = beginDate;}
@Column(name="enddate")
public Date getEndDate() {return endDate;}
public void setEndDate(Date endDate) {this.endDate = endDate;}
@Override
public int hashCode() {
return this.paperName.hashCode()
+this.statType.hashCode()
+this.beginDate.hashCode()
+this.endDate.hashCode();
}
@Override
public boolean equals(Object other) {
if ((other==null)||!(other instanceof StatsPK ))return false;
StatsPK statsPK = (StatsPK)other;
return (
this.paperName.equals(statsPK.paperName) &&
this.statType.equals(statsPK.statType) &&
this.beginDate.getTime()==statsPK.beginDate.getTime() &&
this.endDate.getTime()==statsPK.endDate.getTime()
);
}
now you can see the stattype is the main diffrence , i have many PK which that is the only diffrence the same paper can and should have the same exact PK and only differ on the type and value
when i run per stattype it's all good beside the fact i'm doing xTimeOfType
DB saves data no problem no violation of key , for some reason when i do all type of stats per papername at one time it fails ok PK
Code:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
any idea ?