hi,

thanks for the replay

see in line



2009/1/16 Simone Gianni <[email protected]>

> Hi Håkon,
> is the role_id property in the Role entity annotated with @Id or in any
> other way considered an ID by OpenJPA?

role_id id annotated with @Id

>
>
> Are you adding roles to new users creating new instances of the Role
> classes (like User u = new User(); u.addRole(new Role(Roles.ADMIN)); .. ) or
> getting preexisting Role entities from the database?
>

yes




>
> If you are creating new Role(..) every time, OpenJPA properly supposes that
> is a new row to add to the table.
>

So I've got get a role from the db and assign this to the users role

Role r1 = roledao.find("Admin")

user.addRole.(r1)

something like this?

Or is it possible to annotate this in a way?


>
> Hope this helps,
> Simone
>
>
> Håkon Sagehaug wrote:
>
>> Hi
>>
>> I've got the following setup. A user entity and a role entity. The user
>> has
>> a collection of Role, annotated like this
>>
>>
>> public class User{
>>
>>        ....
>>       @ManyToMany(cascade = CascadeType.ALL)
>>         private Collection<Role> roles = new HashSet<Role>();
>>
>> }
>>
>> public Role {
>>       private int role_id;
>>
>>    @Column(name = "role")
>>    private Roles role;
>> }
>>
>> Where Roles is a enum, with the possible roles. So first of all is this
>> the
>> correct setup if I also want to have many users been able to have the same
>> role?
>>
>> e.g User 1, Role:Admin,User,Tester
>>       User2, Role:Admin,Tester
>>
>> So when persisting a new user the role is also persists the Role object
>> even
>> if there is one from before. so in the example above the Admin and tester
>> role would be inserted twice, and I of course want them to be inserted
>> just
>> once. Is there a way to do this? Should  annotate the Role entity with
>> something more?
>>
>> cheers, Håkon
>>
>>
>>
>>
>
>
> --
> Simone Gianni            CEO Semeru s.r.l.           Apache Committer
> http://www.simonegianni.it/
>
>


-- 
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)

Reply via email to