-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: 'Form based Authentication' with User and Role Mappings
PostPosted: Wed Apr 13, 2005 8:06 pm 
Newbie

Joined: Mon Apr 11, 2005 12:01 am
Posts: 1
Hi,

I am trying to use 'Form based Authentication' with User and Role tables created with Hibernate3. In my User and Role tables I want to use a unique DB generated id as the primary key. However, to get 'Form based Authentication' to work I need to define the relationship between users and roles using user-name and role-name fields instead of primary keys (see user_roles table for details).

I am stuck trying to generate foreign key constraints on the user and role names in the user_roles table. Either I get no foreign key constraints or the constraints end up with primary key (id) of user and role tables. What kind of SET mapping should I have inside the user mapping to generate the foreign key constraints on user_name and role_name? Is there a better way to accomplish this in hibernate mappings?

Thanks in Advance,
Baldeep

Code:
//--------------------DESIRED SQL TABLE STRUCTURE--------------------
TABLE users (
  id    INTEGER   NOT NULL,
  name  VARCHAR   NOT NULL,
  ...
  CONSTRAINT pk_users PRIMARY KEY (id)
);
TABLE roles {
  id    INTEGER   NOT NULL,
  name  VARCHAR   NOT NULL,
  ...
  CONSTRAINT pk_roles PRIMARY KEY (id)
);
TABLE user_roles {
  user_name   VARCHAR   NOT NULL,
  role_name   VARCHAR   NOT NULL,
  CONSTRAINT fk1_user_roles FOREIGN KEY (user_name) REFERENCES users(name),
  CONSTRAINT fk2_user_roles FOREIGN KEY (role_name) REFERENCES roles(name)
);


//--------------------CURRENT HIBERNATE MAPPINGS--------------------
<class name="org.abc.User" table="users">
  <id name="id" unsaved-value="-1">
    <generator class="native"/>
  </id>
  <property name="name" not-null="true" unique="true"/>
  ...
  <set name="roles" table="roles">
    <key column="name" property-ref="name"/>
    <many-to-many column="role_name" class="org.abc.Role"/>
  </set>
</class>

<class name="org.abc.Role" table="roles">
  <id name="id" unsaved-value="-1">
    <generator class="native"/>
  </id>
  <property name="name" not-null="true" unique="true"/>
  ...
</class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.