Hibernate version:
1.2.1.4
Mapping documents:
Code:
<set cascade="none" name="GEMessages" lazy="true" table="MessagesForUsers">
<key column="UserID"/>
<many-to-many class="Message" column="MessageID" where="GEMessage = 1 AND DateValidFrom <= GETDATE() AND (DateValidTo IS NULL OR DateValidTo > GETDATE())"/>
</set>
<set cascade="none" name="PCAMessages" lazy="true" table="MessagesForUsers">
<key column="UserID"/>
<many-to-many class="Message" column="MessageID" where="GEMessage = 0 AND DateValidFrom <= GETDATE() AND (DateValidTo IS NULL OR DateValidTo > GETDATE())"/>
</set>
Code between sessionFactory.openSession() and session.close():
User user = session.load(1);
foreach (Message message in user.GEMessages)
{
user.GeMessages.Remove(message);
}
session.Flush()
Full stack trace of any exception that occurs:
Name and version of the database you are using:
SQL Server 2005
The generated SQL (show_sql=true):
exec sp_executesql N'DELETE FROM MessagesForUsers WHERE UserID = @p0 AND MessageID = @p1',N'@p0 int,@p1 int',@p0=10026131,@p1=2
exec sp_executesql N'DELETE FROM MessagesForUsers WHERE UserID = @p0',N'@p0 int',@p0=10026131
The Problem
I have to sets on a class that are pulled from the same mapping table but are limited on the many-to-many. If i have elements in both sets and empty out the whole set nhibernate will delete using the second query and not the first, which is what it used whilst there where still items in the collection. Now i know i can hack round this by using a third collection to contain the full unconstrained list but i would prefer it did do the delete all and would explicitly delete each one.
Thanks in advance for any help that can be rendered towards solving this problem.