After a few more tests, i've realised that even if I change the EmbeddedID to something that is not in the table, it still successfully completes and returns the Updated
message...even though that record, based on the primary keys, does not exist.
Here are my entity classes:
package au.com.statewater.koncentrator.entity;
// Generated 20/11/2009 10:56:16 AM by Hibernate Tools 3.2.4.GA
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
/**
* Reading generated by hbm2java
*/
@Entity
@Table(name = "MANOPSREAD")
public class Reading implements java.io.Serializable {
/**
* Auto-Generated
*/
private static final long serialVersionUID = 7335804846297650405L;
private ReadingId id;
private Site site;
private Variable variable;
private String value;
public Reading() {
}
public Reading(ReadingId id, Site site, Variable variable) {
this.id = id;
this.site = site;
this.variable = variable;
}
public Reading(ReadingId id, Site site, Variable variable, String value) {
this.id = id;
this.site = site;
this.variable = variable;
this.value = value;
}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "time", column = @Column(name = "VTIME", nullable = false, length = 20)),
@AttributeOverride(name = "date", column = @Column(name = "VDATE", nullable = false, length = 20)),
@AttributeOverride(name = "variableId", column = @Column(name = "VARID", nullable = false, length = 10)),
@AttributeOverride(name = "siteId", column = @Column(name = "SITEID", nullable = false, length = 10))})
@NotNull
public ReadingId getId() {
return this.id;
}
public void setId(ReadingId id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITEID", nullable = false, insertable = false, updatable = false)
@NotNull
public Site getSite() {
return this.site;
}
public void setSite(Site site) {
this.site = site;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "VARID", nullable = false, insertable = false, updatable = false)
@NotNull
public Variable getVariable() {
return this.variable;
}
public void setVariable(Variable variable) {
this.variable = variable;
}
@Column(name = "SVALUE", length = 10)
@Length(max = 10)
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
@Transient
public Date getDate() {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
try {
return df.parse(getId().getDate() + getId().getTime());
} catch (ParseException e) {
System.out.println("Parse Exception Caught while getting Variable Date: " + e.toString());
return null;
}
}
}
package au.com.statewater.koncentrator.entity;
// Generated 20/11/2009 10:56:16 AM by Hibernate Tools 3.2.4.GA
import javax.persistence.Column;
import javax.persistence.Embeddable;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
/**
* ReadingId generated by hbm2java
*/
@Embeddable
public class ReadingId implements java.io.Serializable {
/**
* Auto-Generated
*/
private static final long serialVersionUID = -4580171058168490886L;
private String time;
private String date;
private String variableId;
private String siteId;
public ReadingId() {
}
public ReadingId(String variableId, String siteId) {
this.variableId = variableId;
this.siteId = siteId;
}
public ReadingId(String time, String date, String variableId, String siteId) {
this.time = time;
this.date = date;
this.variableId = variableId;
this.siteId = siteId;
}
@Column(name = "VTIME", nullable = false, length = 20)
@NotNull
@Length(max = 20)
public String getTime() {
return this.time;
}
public void setTime(String time) {
this.time = time;
}
@Column(name = "VDATE", nullable = false, length = 20)
@NotNull
@Length(max = 20)
public String getDate() {
return this.date;
}
public void setDate(String date) {
this.date = date;
}
@Column(name = "VARID", nullable = false, length = 10)
@NotNull
@Length(max = 10)
public String getVariableId() {
return this.variableId;
}
public void setVariableId(String variableId) {
this.variableId = variableId;
}
@Column(name = "SITEID", nullable = false, length = 10)
@NotNull
@Length(max = 10)
public String getSiteId() {
return this.siteId;
}
public void setSiteId(String siteId) {
this.siteId = siteId;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof ReadingId))
return false;
ReadingId castOther = (ReadingId) other;
return ((this.getTime() == castOther.getTime()) || (this.getTime() != null
&& castOther.getTime() != null && this.getTime().equals(
castOther.getTime())))
&& ((this.getDate() == castOther.getDate()) || (this.getDate() != null
&& castOther.getDate() != null && this.getDate()
.equals(castOther.getDate())))
&& ((this.getVariableId() == castOther.getVariableId()) || (this
.getVariableId() != null
&& castOther.getVariableId() != null && this
.getVariableId().equals(castOther.getVariableId())))
&& ((this.getSiteId() == castOther.getSiteId()) || (this
.getSiteId() != null
&& castOther.getSiteId() != null && this.getSiteId()
.equals(castOther.getSiteId())));
}
public int hashCode() {
int result = 17;
result = 37 * result
+ (getTime() == null ? 0 : this.getTime().hashCode());
result = 37 * result
+ (getDate() == null ? 0 : this.getDate().hashCode());
result = 37
* result
+ (getVariableId() == null ? 0 : this.getVariableId()
.hashCode());
result = 37 * result
+ (getSiteId() == null ? 0 : this.getSiteId().hashCode());
return result;
}
}
Any help would be much appreciated.
Charlie