I'm not sure if I'm missunderstanding the definition of the cascade attribute, but I have this problem:
I have a M:N relation and don't want that any changes to the relationship are managed by Hibernate/JPA.
One side is mapped by:
Code:
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "aktens")
public Set<Doktab> getDoktabs() {
return this.doktabs;
}
The other side:
Code:
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name="AKTEDOKID",
joinColumns = {@JoinColumn(name = "VDOKID")},
inverseJoinColumns = {@JoinColumn(name = "AKTEID")})
public Set<Akten> getAktens() {
return this.aktens;
}
The link is working and I'm able to get the Akten / Doktab Objects from any side.
Problem is: when I change the Set behind getAktens than those changes are written to the DB.
e.g.:
Code:
@Transactional
public Doktab getDoktabByVdokid(BigDecimal vdokid, boolean loadAkten) {
Doktab doktab = doktabDao.findById(vdokid);
doktab.setAktens(null);
return doktab;
}
Result:
17:30:38,913 INFO [STDOUT] Hibernate: select [...] from doktab where doktab0_.VDOKID=?
17:30:39,083 INFO [STDOUT] Hibernate: delete from AKTEDOKID where VDOKID=?
It deletes the relation...
Why? The reference doc says that no cascading operations are executed when the cascade type isn't given. I was assuming that the Set<Akten> is ignored?
Background: I want to transfer the object to the client and I don't need the set there. I'm working with it on the server though.