So it was, as I expected, it was my mistake. The "To many" check box was checked on one relationship of the USER_ROLE's two relationships. So instead of having a to one relationship to User and a to one relationship to Role. The join table was a to many to Role, which Cayenne then managed by marking that relationship as "read-only". This caused the insert on the read-only side of the relationship to fail.
One thing that became very clear is that it would be really nice, really, really nice to be able to open two (or more) projects in the modeler at the same time. It's exceptionally difficult to do comparisons between attributes and relationships in two different models when you have to close one model to open the other. I ended up doing screen captures to compare one to the live open project. This worked but was exceptionally painful. Second is that in your model, you don't have the join table set up to have a compound primary key. I changed mine to also not have that primary key flag set, but when I save the modeler chides me about the table not having a primary key. I'm using Derby, you're using H2, but I'm surprised the modeler doesn't complain when your model gets saved. Odd.. Tony On Mon, Aug 5, 2013 at 7:31 PM, Michael Gentry <mgen...@masslight.net>wrote: > Hi Tony, > > Does your UserRole have more than 2 FKs in it? Did you map UserRole > to a Java class in addition to the DB mapping or do you just have the > DB mapping? You should be able to do what you want. I happen to have > an old working example here that does exactly what you are describing: > > > https://github.com/mrg/cbe/blob/master/InsertingObjects/ManyToMany/src/main/java/cbe/inserting/ManyToMany.java > > The complete project has a model you can reference, too. > > mrg > > On Mon, Aug 5, 2013 at 7:03 PM, Tony Giaccone <tgiacc...@gmail.com> wrote: > > > > I have a User a Role and a UserRole. UserRole represents the Join Table > between the two. > > > > The User has a flattened relationship through UserRole to Roles. It's > marked as to many, list. > > > > The Role had a flattened relationship to Users it's marked in the > modeler as to many, read-only, list. > > > > > > I want to add a standard role to the user. I fetch the role, create the > user. The use: > > > > newUser.addToRoles(userRole); > > context.commitChanges(); > > > > And an exception gets thrown. > > > > Cannot set the read-only flattened relationship 'users' in ObjEntity > 'Role' > > > > What am I missing? Do I need accessors for the UserRole? I thought I > could Dispose of that class. I'm confused. > > > > Tony Giaccone > > >