One other thing to note is that Model.merge actually creates a managed copy of whatever it merges. The original object you pass to it is left completely unchanged. So if you do
def doSomething(student : Student) = { Model.merge(student) student.courses.add(...) student.balance += 1000000 } None of those changes will show up since you're not working on the managed copy. What you would really want to do is something like def doSomething(student : Student) = { val merged = Model.merge(student) merged.courses.add(...) merged.balance += 1000000 } Derek On Mon, Sep 29, 2008 at 7:48 AM, Derek Chen-Becker <[EMAIL PROTECTED]>wrote: > 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 liftweb@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---