10:33 PM - (no subject)
Today was an interesting day at work. I managed to get Cayenne working properly for a Project -> User mapping through some intermediate tables. There were few tricks involved. First, I had to modify the User class within Cayenne to explicitly have a mapping for the Primary key. This allows you to do an Expression.fromString and refer to the primary key. Second, I had to do a double mapping using the relationship name between the project and the mapping table then the mapping table to user table relationship. The context had to be the name from the project end and from the mapping table end to the user table. (left to right... )
One problem I had early on was that we also have a user_id stored as the "owner" with a relationship in the project table. That means there's a direct relationship and an indirect relationship between project and user.
The idea here was to map all the projects that the User can access. The mapping table contains a PK, user_id and project_id. A user can potentially access many projects. We knew the user id of the user logged in from the session (username would work too and require less work, but could not benefit from the database indexes).
This sounds trivial, but there is almost no documentation on something like this with Cayenne. Those apache developers need to get up some real examples of Cayenne apps.