I don't think what you want is possible because it goes against concepts of row indentity and referential integrity.

A foreign key in one table implies a relation to the primary key in the other table, and there can be only one primary key.

The normal way to specify the relationship you want is to add a user id attribute to the UserRole class and use the inverse-foreignkey attribute in the user roles' collection descriptor.

Pulat

Sean Dockery wrote:
Hello.

I've searched the gmane archives, but I was unable to find any messages related to my question.

Suppose that I have the following classes...

public class User {
private Integer id; // primary key field
private String username; // alternate key field
private Collection userRoles; // collection of UserRole objects related by username
};


public class UserRole {
    private String username; // foreign key
    private String rolename;
}

...and I wanted to relate User and UserRole in a repository mapping based on the equality of the username fields in both User and UserRole. Can this exact schema be handled through a repository mapping? (Does fk-pointing-to-this-class work without using an indirection-table? Is there an alternative?)

Most of the rest of the data model in the application uses User.id as a foreign key, so we can't easily change the primary key of the user table.
The UserRole fields were chosen for compatibility with Tomcat JDBCRealm-like declarative security implementations.
The only way that I can see to work around this problem is to duplicate the User.id field in the UserRole table, along with the username.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to