-->
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.  [ 2 posts ] 
Author Message
 Post subject: Session.setReadOnly and ManyToMany mapping
PostPosted: Tue Jan 25, 2011 12:59 am 
Newbie

Joined: Tue Jan 25, 2011 12:50 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Session.setReadOnly and ManyToMany mapping
PostPosted: Tue Jan 25, 2011 1:16 am 
Newbie

Joined: Tue Jan 25, 2011 12:50 am
Posts: 2
Ok, I think I've worked around this problem. If I call this, then the delete is not called:

HibernateUtils.getCurrentSession().setFlushMode(FlushMode.MANUAL);

Thanks!


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

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.