I have an embeddable class defined as follows:
@Embeddable
public class OrderLine implements Serializable {
private static final long serialVersionUID = 1L;
@Column(nullable = false, updatable = false)
private String company;
@ManyToOne(optional = false)
@JoinColumn(updatable = false, nullable = false)
private Product product;
@Lob
@Column(insertable = false)
private byte[] report;
@Column(insertable = false)
private Date satisfied;
public OrderLine() {
}
public OrderLine(String company, Product product) {
this.company = company;
this.product = product;
}
public String getCompany() {
return company;
}
public Product getProduct() {
return product;
}
public byte[] getReport() {
return report;
}
public void setReport(byte[] report) {
this.report = report;
}
public Date getSatisfied() {
return satisfied;
}
public void setSatisfied(Date satisfied) {
this.satisfied = satisfied;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if ((object == null) || (object.getClass() != this.getClass())) {
return false;
}
OrderLine orderline = (OrderLine) object;
return (this.company == orderline.getCompany() || company
.equals(orderline.getCompany())
&& (this.product == orderline.getProduct() || this.product
.equals(orderline.getProduct())));
}
@Override
public int hashCode() {
int result = 7;
result = 31 * result + (null == company ? 0 : company.hashCode());
result = 31 * result + (null == product ? 0 : product.hashCode());
return result;
}
}
The primary key is defined in the parent class:
@CollectionOfElements
@JoinTable(name = "OrderLine", joinColumns = @JoinColumn(name = ORDER_NO))
@CollectionId(columns = @Column(name = "orderline_id"), type = @Type(type = "long"), generator = "sequence")
private Collection<OrderLine> orderLines = new HashSet<OrderLine>();
1) If I add any OrderLines then the "insertable" flag is ignored:
insert
into
OrderLine
(order_no, orderline_id, company, product_id, report, satisfied)
values
(?, ?, ?, ?, ?, ?)
I would have expected only order_no, orderline_id, company and product_id to be inserted.
2) If I update any orderlines then all the orderlines are deleted and reinserted:
delete
from
OrderLine
where
orderline_id=?
insert
into
OrderLine
(order_no, orderline_id, company, product_id, report, satisfied)
values
(?, ?, ?, ?, ?, ?)
Why no update?
Thanks
Mark
|