Announcement Announcement Module
No announcement yet.
Spring Security standard table fields VS Hibernate required fields Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Security standard table fields VS Hibernate required fields

    Looks like clash between standard Spring Security DB tables fields and requirements of Hibernate for fields,in particularly, id field.

    From one side, have standard Spring tables(
    create table users(
          username varchar_ignorecase(50) not null primary key,
          password varchar_ignorecase(50) not null,
          enabled boolean not null);
      create table authorities (
          username varchar_ignorecase(50) not null,
          authority varchar_ignorecase(50) not null,
          constraint fk_authorities_users foreign key(username) references users(username));
          create unique index ix_auth_username on authorities (username,authority);
    these tables don't contain id fields.

    From other side,have Hibernate configuration:

        <class name="model.Authorities" table="authorities">
            <id name="username" column="username"/>
            <property name="authority" column="authority"/>
            <many-to-one name="userDetails" class="model.UserDetails" not-null="false" column="username"/>
        <class name="model.UserDetails" table="users">
            <id name="username" column="username"/>
            <property name="password" column="password"/>
            <property name="enabled" column="enabled"/>
            <set name="authorities" cascade="all" inverse="true">
            	<key column="username" not-null="true"/>
            	<one-to-many class="model.Authorities"/>
    Exception got:
    Code: ids for this class must be manually assigned before calling save(): model.Authorities

    What is the best practice?
    This case(in order to fix problem) I should add to Hibernate config following:
     <id name="id">
                <generator class="assigned"/>
    Should I make changes to standard Spring tables and add id fields there?
    Is it acceptable or there is other more gracefull solution?
    Last edited by sergionni; Dec 8th, 2011, 05:39 AM.