Dear Forum,
I have an issue where I want have an object, User, with ManyToMany relationship, Addresses. Now, I grab the user with something like this:
User object = (User)session.load(User.class, id);
I then set the session to read only for that object:
session.setReadOnly(object, true);
Then I use reflection to setAddresses(new ArrayList()); After the transaction commit, I suddenly see this pop up in my sql trace:
Hibernate: delete from user_addresses where user_id=?
Why is it trying to delete my addresses even though I've set the read only flag? I thought this would prevent any dirty checking on any part of the object? And would not persist anything out? Or delete? It works perfectly if I do something like setName(""); The name is not persisted as expected. I do not want to persist the empty list, there just happens to be times when I want the user's list of addresses to be empty. Is there any way around this weirdness? Or does anyone have any idea why this happens on my ManyToMany object? Here is the annotations for it:
@ManyToMany @IndexColumn(name="user_address_index") @JoinTable( name="user_addresses", joinColumns=@JoinColumn(name="user_id"), inverseJoinColumns=@JoinColumn(name="address_id") ) private List<Address> addresses = null;
Thank you again for any help.
Sincerely, David
|