On Tue, Sep 6, 2011 at 6:55 PM, Mike Kienenberger <mkien...@gmail.com> wrote: > It's probably also worth noting that, as MIchael's example shows, you > do not need to set both sides of the relationship.
OK. I have done this while investigating my error - I thought this might be the case (like I had once in Hibernate or Toplink world) > > On Tue, Sep 6, 2011 at 12:46 PM, Christian Grobmeier > <grobme...@gmail.com> wrote: >> Hi Michael, >> >>> I suspect it is because you are creating the UserRole outside the >>> DataContext. Try something like: >>> >>> UserRoles userRoles = user.getObjectContext.newObject(UserRoles.class); >>> userRoles.setUser(user); >>> userRoles.setRole(role); >> >> actually this might be the case - I will test this. This would explain >> why it gets into the database but is missed in the context >> >> Cheers >> >>> >>> mrg >>> >>> >>> On Tue, Sep 6, 2011 at 11:14 AM, Christian Grobmeier >>> <grobme...@gmail.com> wrote: >>>> Folks, >>>> >>>> I need your help. An error in my app bugs me and I am looking >>>> desperately were it could happen. >>>> >>>> The use case is: >>>> - create a user >>>> - create a user_role object >>>> - select one of the existing roles >>>> - connect all together and commit >>>> >>>> I see that all values are correct in the database (mysql console) >>>> >>>> But after the user registered, my app fails with the error "no role". >>>> >>>> What I do is basically: >>>> >>>> ur = User.getUserRoles(); >>>> foreach ur: >>>> r = ur.getRole() >>>> >>>> >>>> And the r reference is null. I am not sure what I am doing wrong. Any >>>> hints what I could check in my Cayenne app? >>>> >>>> I add a role to a user liek this: >>>> >>>> User user ... >>>> >>>> UserRoles userRoles = new UserRoles(); >>>> userRoles.setUser(user); >>>> userRoles.setRole(role); >>>> user.addToUserRoles(userRoles); >>>> role.addToRolesToJoin(userRoles); >>>> >>>> Any hints highly apprecitated - thanks in advance >>>> >>>> Christian >>>> >>> >> >> >> >> -- >> http://www.grobmeier.de >> > -- http://www.grobmeier.de