Argh! Stupid gmail hotkeys... Here's what I wanted to say:

class Student {
  // ... everything else up here ...

  @ManyToMany{ val targetEntity = classOf[Course] }
  var courses : java.util.Set[Course] = new java.util.HashSet[Course]
}

class Course {
  // ... everything else up here ...

  @ManyToMany { val targetEntity = classOf[Student], val mappedBy =
"courses" }
  var students : java.util.Set[Student] = new java.util.HashSet[Student]
}

Since the student is the owning side, if you want to delete the relationship
you need to do it from the student:

def unenroll (student : Student, course : Course ) =
student.courses.remove(course)

this assumes that student and course are both managed in the EM session
already. If neither is, you could do

def unenroll (student : Student, course : Course) = {
  student.courses.remove(course)
  Model.merge(student)
}

The big thing to remember is that none of these operations actually do
anything to the database unless they happen within a transaction. In the
demo code I've put up this should happen automatically. Having said all of
this, what issue are you running into?

Derek


On Mon, Sep 29, 2008 at 7:35 AM, Derek Chen-Becker <[EMAIL PROTECTED]>wrote:

> With many to many you still have an "owning" side that's responsible for
> things. For instance, given the following classes:
>
> class Student {
>
>
>
> On Mon, Sep 29, 2008 at 6:17 AM, Tim Perrett <[EMAIL PROTECTED]> wrote:
>
>>
>> Hey Guys,
>>
>> Im having a few problems doing a many-to-many deletion using JPA...
>> can anyone point me in the right direction?
>>
>> Thanks
>>
>> Tim
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to