You appear to be correct, but the app works fine with this current setting - I
don't know why (it shouldn't), but it does. I'll change this to the following
and verify everything still works:
* @hibernate.bag name="roles" table="user_role" cascade="none"
* inverse="true" lazy="true"
* @hibernate.collection-key column="username"
* @hibernate.collection-one-to-many
class="org.appfuse.persistence.UserRole"
Matt
--- Simon See <[EMAIL PROTECTED]> wrote:
> Matt,
>
> Just a quick confirmation here. I'm beginning to be quite sure that
> there's a 1-to-M relationship bug between User and its UserRoles.
>
> Notice your mapping goes like this: -
> /**
> * Returns the user's roles.
> * @return List
> *
> * @hibernate.bag name="roles" table="user_role" cascade="none"
> inverse="true"
> * lazy="true"
> * @hibernate.collection-key column="id"
> * @hibernate.collection-one-to-many
> class="org.appfuse.persistence.UserRole"
> */
> public List getRoles() {
> return roles;
> }
>
> Where as if you look at Roles.id, it's actually its primary key and id.
> This causes a 'forced' 1-to-1 mapping instead. Example, UserA.id() is 1
> and its UserRole1.id() is 1. This makes them related. However, if you
> add another UserRole, say UserRole2 which has id is 2., UserA can never
> be associated with it as UserA's id is 1.
>
> The right relationship should have a foreign key in UserRole pointing
> back to User like this: -
>
> /**
> * Returns the user's roles.
> * @return List
> *
> * @hibernate.bag name="roles" table="user_role" cascade="none"
> inverse="true"
> * lazy="true"
> * @hibernate.collection-key column="user_id"
> * @hibernate.collection-one-to-many
> class="org.appfuse.persistence.UserRole"
> */
> public List getRoles() {
> return roles;
> }
>
> This means your user_role table should have an additional foreign key
> 'user_id".
>
> Agree :) ?
>
> You can try UserRole adding/deleting functionality. It doesn't work at
> all. It keeps on sticking to the role that it originally was associated
> with.
> .
> Thank you.
>
> Simon See
>
> Are your J2EE 'deliverables' giving you insanity?
> http://www.see-consulting.com
>
> Handset: (6) 012 376 7192
>
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
Struts-apps mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/struts-apps