I have seen your question and Alex's reply and wonder whether you have solved the problem.
I'm a little confusing by your user-role's 1:N relationship. I think in most applications it should be N:N, for one user may be in many roles and many users may in the same role.
OK, let's first suppose you really need 1:N. In this situation, first you need a primary key and declare it as the PK field of your RoleBean, second you should not(and never) declare your foreign key column(such as pricinpleId) in your db table as a cmp field in your RoleBean(it's important!). So, when you want to add a new Role in your ***application***, you should only call roleBean.create(PK, name, ...) without foreign key and the result is your foreign key column in your table is null. And, when you want to add a new role to your ***User***, you should first have a UserBean(create or find one), and then call user.getRoles to get the roles' Collection, after that, find a RoleBean( such as by findByPrimaryKey), call your roles' Collection's add method and pass the RoleBean you found as parameter( like roleCollection.add(roleBean)). This way, jboss will auto set the value of foreign key column(pricinple) in your role table as the value of your user's PK. Please pay attention to the difference of the word with "***" I marked.
If your really requirement is a N:N relationship, it will be more complex and I can help you if you want.
Hope it's helpful and good luck!
Gene
kiuma wrote:
_________________________________________________________________Hi all, I've the following problem:I've mapped principals and roles in a 1..n relationship When I try to add a role using: roleHome.create( new RoleData(pPrincipalId, "caller_principal", "CallerPrincipal") ); I've the following error back 08:53:40,972 ERROR [LogInterceptor] EJBException: javax.ejb.EJBException: Creation Role failure: Could not create entity:java.sql.SQLException: ERROR: Attribute 'principalid' specified more than once Since I'm already a newbie I can't figure out what this message means. My cmr generated by xdoclet is: for jboss: <relationships> <ejb-relation> <ejb-relation-name>user-roles</ejb-relation-name> <foreign-key-mapping/> <ejb-relationship-role> <ejb-relationship-role-name>role-has-user</ejb-relationship-role-name> <key-fields/> </ejb-relationship-role> <ejb-relationship-role> <ejb-relationship-role-name>user-has-role</ejb-relationship-role-name> <key-fields> <key-field> <field-name>principalId</field-name> <column-name>principalid</column-name> </key-field> </key-fields> </ejb-relationship-role> </ejb-relation> </relationships> Obviously if I don't use the relationship in my code I can add that role.
Broadband? Dial-up? Get reliable MSN Internet Access. http://resourcecenter.msn.com/access/plans/default.asp
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user