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.  [ 1 post ] 
Author Message
 Post subject: Remove item from where filtered many-to-many
PostPosted: Mon Mar 10, 2008 1:17 pm 
Newbie

Joined: Tue Mar 04, 2008 11:02 am
Posts: 1
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 &lt;= GETDATE() AND (DateValidTo IS NULL OR DateValidTo &gt; 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 &lt;= GETDATE() AND (DateValidTo IS NULL OR DateValidTo &gt; 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.


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

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.