-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @Embeddable, insertable and updatable ignored
PostPosted: Wed Sep 17, 2008 12:53 pm 
Newbie

Joined: Wed Feb 23, 2005 9:01 am
Posts: 9
Location: London
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.