-
1. Re: Dissolving a many to many relationship
chrismalan Jun 28, 2006 12:13 AM (in response to chrismalan)To further clarify, the following two SQL queries do what I want done:
"delete from STUDENT_SUBJECT;" and
"delete from STUDENT_CLASS;"
The second one is not mentioned in the post, but if I can get one to work, so will the other.
There is a method that removes any number of stidents (comma separated) from a subject and also from the class for a subject. Putting the code for this in a loop for all subjects does not work with the same exception as above.
This should be possible, and preferably without the looping - more something like the native delete query, which is not implemented in the EJB3/JBoss version I use (4.0.3)
Maybe I should create explicit classes for the relationship tables and one to many relationships. I think I can get that to work. What a hassle. It will mean a lot of re-writing. -
2. Re: Dissolving a many to many relationship
squishy Jun 28, 2006 2:35 AM (in response to chrismalan)I think you get the ConcurrentModificationException because you remove objects from the list while you're iterating over it.
If you go through the list with a simplefor (int i = 0; i < subjects.size(); i++)
maybe it will work? -
3. Re: Dissolving a many to many relationship
chrismalan Jun 28, 2006 6:01 AM (in response to chrismalan)Hi Squishy,
Thanks very much. That was it. However, before the code posted above I had a for(Subject s : subjects). That threw the same exceptions. This time I got a Set of subjects and turned it into an Object array and for looped through that - no problem. It didn't take long to execute, either.
Thanks again, -
4. Re: Dissolving a many to many relationship
squishy Jun 28, 2006 8:13 AM (in response to chrismalan)Don't you have a relationship on EJB level so you can do student.getSubjects() instead of going through the trouble of doing a query? Looks awful complicated to me :)
-
5. Re: Dissolving a many to many relationship
chrismalan Jun 29, 2006 10:21 PM (in response to chrismalan)Yes, I have. Then I did a subjects.clear() No exceptions or anything, but the student-subject relationship was still there in the relationship table in MySQL.
I think I may even have called flush(). I did call subjects.size() before clearing.