I have this entity which has a
Code:
@ManyToMany
association; below is a snippet of the entity with relevant parts
Code:
public class Label implements Serializable,Comparable<Label>{
private static final long serialVersionUID = 123L;
private String text;
@Column(updatable=false)
private String code;
@Id
@Column(name="label_id")
@SequenceGenerator(name = "labelSeq", sequenceName = "label_id_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "labelSeq")
private Long id;
@Column(name="client_id",updatable=false)
private Long clientId;
@org.hibernate.annotations.Type(type="boolean")
@Column(name="is_system_label",updatable=false)
private boolean isSystemLabel;
@ManyToMany
@JoinTable(
name="labels_ctg_amounts",
joinColumns = {@JoinColumn(name = "label_id")},
inverseJoinColumns = {@JoinColumn(name = "ctg_id")}
)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.EXTRA)
private Set<Contingency> contingencies;
Now when I do a simple update on a Label with code like this:
Code:
Label l = new Label();
l.setId(52000L);
l.setText("test update capability");
session.saveOrUpdate(l);
I get the following partial dump:
Code:
16:26:08.319 [main] DEBUG org.hibernate.SQL -
update
labels
set
text=?
where
label_id=?
Hibernate:
update
labels
set
text=?
where
label_id=?
16:26:08.460 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
16:26:08.476 [main] DEBUG org.hibernate.jdbc.Expectations - success of batch update unknown: 0
16:26:08.476 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:26:08.476 [main] DEBUG o.h.p.c.AbstractCollectionPersister - Deleting collection: [net.taxstream.fin48.domain.Label.contingencies#52000]
16:26:08.476 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
16:26:08.476 [main] DEBUG org.hibernate.SQL -
delete
from
labels_ctg_amounts
where
label_id=?
Hibernate:
delete
from
labels_ctg_amounts
where
label_id=?
16:26:08.476 [main] DEBUG o.h.p.c.AbstractCollectionPersister - done deleting collection
I don't want the rows in the link table deleted. However if I use a proxy like this:
Code:
Label l = (Label)session.load(52000L);
l.setText("test update capability");
session.saveOrUpdate(l);
This works just great as I would expect -- a simple update of text and that's it. But i cannot rely on this second method as the updated Label object is bound to values in the Spring controller therefore using this second method would require me to set the properties in the proxy with the properties from the bound object, something like this:
Code:
Label l = (Label)session.load(52000L);;
l.setText(boundLabel.getText());//boundLabel is bound to values from the client via the Spring controller
...//setting every property is totally unacceptable
Any ideas on how I can resolve this?