You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Julian Wood <wo...@ucalgary.ca> on 2008/03/11 00:18:37 UTC
tapestry-acegi example app question
In the provided example for tapestry-acegi, I have a question about
the GrantedAuthorityBean table. That is, if I add more users which
share roles, each role will create a new row in the GAB table. How can
this be avoided?
I've tried making the authority unique:
@Table(uniqueConstraints = {@UniqueConstraint(columnNames =
{"authority"})})
but hibernate is not clever enough to realize that it should reuse
existing roles, and just throws a constraint exception. I'm looking at
interceptors now. I guess this is really a hibernate question, but I
thought that someone here might have encountered this issue, given its
context in tapestry-hibernate.
Thanks,
J
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: tapestry-acegi example app question (solved)
Posted by Robin Helgelin <lo...@gmail.com>.
On Tue, Mar 11, 2008 at 3:37 AM, Julian Wood <wo...@ucalgary.ca> wrote:
> Hate to answer my own question, but I think the proper relation for:
>
> is:
>
> @ManyToMany( cascade={CascadeType.PERSIST, CascadeType.MERGE} )
>
> You then need to persist your GrantedAuthorityBean independently from
> UserDetails, but that makes sense, and it solves the problem of the
> GrantedAuthorityBean and the join table exploding with duplicate info.
Thanks! I'll update the example.
--
regards,
Robin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: tapestry-acegi example app question (solved)
Posted by Julian Wood <wo...@ucalgary.ca>.
Hate to answer my own question, but I think the proper relation for:
@OneToMany
@Cascade(CascadeType.ALL)
public Collection<GrantedAuthorityBean> getGrantedAuthorities() {
return grantedAuthorities;
}
is:
@ManyToMany( cascade={CascadeType.PERSIST, CascadeType.MERGE} )
You then need to persist your GrantedAuthorityBean independently from
UserDetails, but that makes sense, and it solves the problem of the
GrantedAuthorityBean and the join table exploding with duplicate info.
Thanks,
J
PS. http://www.localhost.nu/svn/public/tapestry5-acegi-example/src/
main/java/nu/localhost/tapestry/acegi/example/entities/
UserDetailsBean.java
On 10-Mar-08, at 5:18 PM, Julian Wood wrote:
> In the provided example for tapestry-acegi, I have a question about
> the GrantedAuthorityBean table. That is, if I add more users which
> share roles, each role will create a new row in the GAB table. How
> can this be avoided?
>
> I've tried making the authority unique:
>
> @Table(uniqueConstraints = {@UniqueConstraint(columnNames =
> {"authority"})})
>
> but hibernate is not clever enough to realize that it should reuse
> existing roles, and just throws a constraint exception. I'm looking
> at interceptors now. I guess this is really a hibernate question,
> but I thought that someone here might have encountered this issue,
> given its context in tapestry-hibernate.
>
> Thanks,
>
> J
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: tapestry-acegi example app question
Posted by Robin Helgelin <lo...@gmail.com>.
On Tue, Mar 11, 2008 at 12:18 AM, Julian Wood <wo...@ucalgary.ca> wrote:
> In the provided example for tapestry-acegi, I have a question about
> the GrantedAuthorityBean table. That is, if I add more users which
> share roles, each role will create a new row in the GAB table. How can
> this be avoided?
Users and Roles are a many-to-many relation ship. You'll need a third
table to normalize the sql. However, as the example app is just an
example, a better approach would be to create a table for the roles.
Users table:
user_id
username
password
Roles table:
role_id
name
Users_Roles tables
user_id
role_id
--
regards,
Robin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org