Re: how to store/save not PKs in the join-tables instead of storing the id's

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Feb 10 2005 - 09:36:33 EST

  • Next message: Gentry, Michael \(Contractor\): "RE: Cache with StoredProcedure cursor parameter"

    Hi Zvonomir,

    Mapping tomcat JDBC realms schema shouldn't be a problem - Cayenne
    supports meaningful PKs mapped as Java object attributes. However there
    maybe some quirks.

    What happens if you mark all these columns as PK?

    user.username
    role.rolename
    join_user_role.role_name
    join_user_role.user_name

    Andrus

    > Hello,
    >
    > after 5 hours trying I don't see any chance to solve my problem by lucky
    > testing.
    > I want to use Tomcats JDBC Realm. For this Login-Mechanism it's
    > necessary to have specific table-names and table-columns and to define
    > them in the server.xml:
    >
    > for example:
    > <Realm className="org.apache.catalina.realm.JDBCRealm"
    > debug="99"
    > driverName="org.gjt.mm.mysql.Driver"
    > connectionURL="jdbc:mysql://localhost/myDatabase"
    > connectionName="My DB Connection"
    > connectionPassword="myPassword"
    > userTable="user" userNameCol="username"
    > userCredCol="password"
    > userRoleTable="join_user_role" roleNameCol="rolename" />
    >
    > I want to use this with cayenne. A user can have many roles. A role can
    > belong to many users.
    > Because of this I use a Join Table (join_user_role).
    >
    > If I do it this way...
    > The column "username" is not the PK in the table user. The PK column in
    >
    > the table user is "id" (auto_pk_supported).
    > The column "rolename" is not the PK in the table role. The PK column in
    >
    > the table role is "id" (auto_pk_supported).
    > The 3 columns in the join table join_user_role are:
    > 1)id (auto_pk_supported)
    > 2)user_id
    > 3)role_id
    >
    > The relationships are:
    > user.id <--> join_user_role.user_id
    > role.id <--> join_user_role.role_id
    >
    > .. then cayenne works fine.
    >
    > But if I want to store the username and rolename in the join-table
    > join_user_role, like that way
    > The relationships are:
    > user.username <--> join_user_role.user_name
    > role.rolename <--> join_user_role.role_name
    >
    > then cayenne gives me an error:
    > org.objectstyle.cayenne.CayenneRuntimeException: [v.1.1RC1 October 3
    > 2004] Cannot set the read-only flattened relationship hasRoles
    > ERROR RegistrationAction: Registration failed!
    >
    >
    > How I can store/save the username and rolename in the join-table instead
    > of storing the id's. I need this for the JDBCRealm.
    >
    > Please help me.
    >
    > Greetings Zvonimir



    This archive was generated by hypermail 2.0.0 : Thu Feb 10 2005 - 09:36:35 EST