-->
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: Many-to-Many with a view as intermediate table
PostPosted: Wed Jul 29, 2009 9:36 am 
Newbie

Joined: Wed Jul 29, 2009 9:25 am
Posts: 9
Hello, I am using many-to-many mapping that are working great like this:
Code:
   <set name="userRules" lazy="false" table="User_Rules" order-by="RuleId asc">
      <key column="UserId"/>
        <many-to-many column="RuleId" class="com.org.hibernate.pojos.RuleBean"/>
        </set>


The problem is when one of this mappings have an intermediate table "User_Rules" that is not really a table, but a view.
The mapping works good when trying to retrieve elemnts of one table from the other.But when I try to delete an element from on of the tables (user for example), it tries to delete the element from the intermediate table ("User_Rules") as well, and it cant bacause in this case it is a view, and it gives me this error:

Code:
WARN  2009-07-29 15:34:18,312 - SQL Error: 0, SQLState: null
ERROR 2009-07-29 15:34:18,312 - Batch entry 0 delete from User_Rules where UserId=66 was aborted.  Call getNextException to see the cause.
WARN  2009-07-29 15:34:18,312 - SQL Error: 0, SQLState: 0A000
ERROR 2009-07-29 15:34:18,312 - ERROR: cannot delete from a view


Is there a way to tell hibernate not to delete elements from the intermediate table?? thanks!!!


Top
 Profile  
 
 Post subject: Re: Many-to-Many with a view as intermediate table
PostPosted: Sat Aug 01, 2009 6:03 am 
Newbie

Joined: Wed Jul 29, 2009 9:25 am
Posts: 9
Isnt there a way to tell hibernate not to delete from the intermediate table in a many-to-many relation?
some thing like

on-delete="cascade",
or
cascade="none",
or
tell hibernate to see a table as a read only table so it never tries to delete an element from there...?

I dont know what else to try but it seems to me like something not so weird, is it?

if impossible... is at least possible to use a many to one relation, for example user to user_rules, and avoid deleting the reference in user_rules when deleting a user?

thanks.


Top
 Profile  
 
 Post subject: Re: Many-to-Many with a view as intermediate table
PostPosted: Sun Aug 02, 2009 10:25 am 
Newbie

Joined: Wed Jul 29, 2009 9:25 am
Posts: 9
I found a 2 years old post with the exact same problem, but no answers, which probably explains better the problem:
https://forums.hibernate.org/viewtopic.php?f=1&t=981204

I also have found a possible solution, which I havent been able to try yet. This would be to use the old delete way:
Code:
session.createQuery("delete from User where User.id=..").executeUpdate()

Some people was complaining that this method dont delete entries from join tables, and that is exactly what I need.


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.