Announcement Announcement Module
Collapse
No announcement yet.
Spring Security standard table fields VS Hibernate required fields Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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(http://static.springsource.org/sprin...ix-schema.html):
    Code:
    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:

    Code:
        <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>
    Code:
        <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"/>
            </set>
        </class>
    Exception got:
    Code:
    org.hibernate.id.IdentifierGenerationException: 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:
    Code:
     <id name="id">
                <generator class="assigned"/>
      </id>
    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, 06:39 AM.
Working...
X