Wed, 8 Jul 2009
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.
Sat, 30 May 2009
10:20 PM - Annoying MySQL issue with jdbc
Ever get this? Cannot convert value '0000-00-00 00:00:00' from column to TIMESTAMP.
The problem is that the MySQL jdbc driver doesn't map it to null. There are flags to the connection that are supposed to do this for you, but I've had no luck getting them to work. I have two timestamp fields on the User table for this site. I wrote a MySQL to java data mapper years ago, but now that I'm converting to Cayenne, I can't use that anymore. Time to fix the database :)