Hi,

Consider the following n-m relationship:

mysql> desc User;
+------------+--------------+-----+
| Field      | Type         | Key |
+------------+--------------+-----+
| userId     | varchar(50)  | PRI |
| password   | varchar(250) |     |
+------------+--------------+-----+

mysql> desc UserRole;
+--------+-------------+-----+
| Field  | Type        | Key |
+--------+-------------+-----+
| userId | varchar(50) | PRI | <- foreign key to User.userId
| roleId | varchar(50) | PRI | <- foreign key to Role.roleId
+--------+-------------+-----+

mysql> desc Role;
+-------------+--------------+-----+
| Field       | Type         | Key |
+-------------+--------------+-----+
| roleId      | varchar(50)  | PRI |
| description | varchar(250) |     |
+-------------+--------------+-----+

Due to my GUI (a multiple selection listbox -- or a picklist; I've another
GUI to add/change the Role's data), I want to make a method call that looks
like create(userId, password, roleIds[]), note that I just have the roleId,
and not the whole Role object/row.

In JDBC, I just need to insert a record in User, and another record in
UserRole (with the given roleId, and the new userId), there's no need to
lookup the Role table.

If I use Castor n-m relationship, I need to look up Role objects using
roleIds, and call a method, such as create(userId, password, roles). This's
a unnecessary overhead (more network traffic and round-trip). n-m works
great only if I need to add a new Role, and bind it to a new User.

I can drop the Role table (it's a dummy table anyway), and use 1:n
relationship. But the dependent object, i.e. UserRole, must have an identity
field (unique), and UserRole will contain only roleId as its only property.
So I cannot make this to behave like an association table, unless I have an
extra primary key column in UserRole.

Any suggestion to model this?

Thanks

Thomas

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to