-->
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.  [ 6 posts ] 
Author Message
 Post subject: many to many and deletions
PostPosted: Tue Nov 25, 2003 2:09 am 
Newbie

Joined: Sat Nov 15, 2003 11:24 pm
Posts: 5
Hi,

I have a many-to-many relationship,. Let


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:47 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Hmmm.... For me both options are identical. In order to implement #1, you need to write query which will return all employees who has specific role and then iterate this list. For #2 you do absolutely the same - you write HQL query which searches for employees who has specific role and pass this query to session.delete() to let Hibernate do the iteration+delete.

So #2 is little less coding but absolutely the same idea. See the sources - session.delete(hqlQuery) has:

Code:
      List list = find(query, values, types);
      int size = list.size();
      for ( int i=0; i<size; i++ ) delete( list.get(i) );


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:11 pm 
Newbie

Joined: Sat Nov 15, 2003 11:24 pm
Posts: 5
Thanks for your answer.

The many-to-many table is generated by Hibernate. I don


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:22 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
You can not delete collection entries with query as far as I know. You need to load parent object and remove entries from its set. Hibernate will update database appropriately.

I suppose your SELECT query should look like


Code:
select employe
from Employee as employee,
  employee.securityLevels as level
  where  level.name = :name


Nost sure though. See http://www.hibernate.org/hib_docs/refer ... anguage-s6 for details


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:25 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Oops,

employee.priveleges as level


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 11:10 pm 
Newbie

Joined: Sat Nov 15, 2003 11:24 pm
Posts: 5
I ended up adding a list of employees (with lazy loading) to the SecurityLevel class.

When I want to reset the privilieges, I empty the list, add the authorized employees, and save the security object.
Everything is being taken care of by Hibernate.

I thought there was a way of doing the same thing without having to declare an employee list in the SecurityLevel class, but apparently not.
Thank you for your help.

-Vincent.


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