-->
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.  [ 3 posts ] 
Author Message
 Post subject: Delete through a view causes SQL Server error
PostPosted: Wed Sep 27, 2006 11:46 am 
Newbie

Joined: Fri Mar 17, 2006 5:23 pm
Posts: 6
I have a class that is mapped to a view. I do this because some of the attributes of the class are denormalized from other tables. When I attempt to delete an instance of my class, I get the following SQL Server error:

View or function 'MooView' is not updatable because the modification affects multiple base tables

Question: Is it possible to change my NHibernate mapping so that the delete is executed against the actual table (Moo) rather than the view (MooView)?

Here's what the relevant portion of my mapping file looks like:

Code:
   <class name="Moo" table="MooView">
      <property name="BaaName" insert="false" update="false" />
   </class>


Note that the class is mapped to a view that spans two tables: Moo and Baa. "BaaName" is a derived value obtained from the Baa table rather than the Moo table, hence it is marked as insert/update = false.

How can I delete an instance of Moo?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
To do that, you'd need to use the sql-delete element under the class element. NHibernate doesn't support that (it was added in hibernate3). So no, you can't use session.delete if you use that view. Either do your denormalization in your mapping file, or use raw SQL.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 15, 2006 9:35 pm 
Newbie

Joined: Sun Oct 15, 2006 9:33 pm
Posts: 1
A bit late, I know, but I'm new here....

You should be able to get around this problem by adding an INSTEAD OF trigger to the view.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.