Hi all,
Hibernate 2.1.1 on servlet on JonAS 3.3.5
I have already tried to look for answers in this forum and the FAQ, but I can't figure out how I have to proceed.
I have two classes Group and User. In Group I have a list of users and in User I have a list of the groups where the user is registered.
Here is the mappings:
Code:
   <class name="HibernateUser" table="usertable">
        <list name="groups" table="usergrouptable" lazy="false">
            <key>
                <column name="uid"/>
            </key>
            <index column="j" type="integer"/>
            <many-to-many class="org.enhydra.shark.usergroup.HibernateGroup">
                <column name="gid"/>
            </many-to-many>
        </list>
    </class>
Code:
    <class name="HibernateGroup" table="grouptable">
       <list name="users" table="usergrouptable" lazy="false">
            <key>
                <column name="gid"/>
            </key>
            <index column="i" type="integer"/>
            <many-to-many class="org.enhydra.shark.usergroup.HibernateUser">
                <column name="uid"/>
            </many-to-many>
        </list>
    </class>
And here are the tables schema:
Code:
--for the association tables
CREATE TABLE "usergrouptable" (
    "uid" character varying(254) NOT NULL,
    "gid" character varying(254) NOT NULL,
    "i" integer,
    "j" integer,
    CONSTRAINT "FK_UserGroupTable_gid_GroupTable" FOREIGN KEY (gid) REFERENCES grouptable(gid) ON UPDATE NO ACTION ON DELETE NO ACTION,
    CONSTRAINT "FK_UserGroupTable_uid_UserTable" FOREIGN KEY (uid) REFERENCES usertable(uid) ON UPDATE NO ACTION ON DELETE NO ACTION,
    CONSTRAINT "PK_UserGroupTable" PRIMARY KEY ("uid","gid")
);
Code:
--for the User
CREATE TABLE "usertable" (
    "uid" character varying(254) NOT NULL,
    "name" character varying(254) NOT NULL,
    "passwd" character varying(254) NOT NULL,
    "email" character varying(254) NOT NULL,
    CONSTRAINT "PK_UserTable" PRIMARY KEY ("uid")
) ;
Code:
--for the User
CREATE TABLE "grouptable" (
    "gid" character varying(254) NOT NULL,
    "description" character varying(254) NOT NULL,
    CONSTRAINT "PK_GroupTable" PRIMARY KEY ("gid")
);
I have a in Group method to addUserToGroup (and this was to try a method in User to addGroupToUser). But when I addUserToGroup, it does not update properly the index column in the table and so the list of groups couldn't retrieve properly too.
What I do for the business code side is:
Code:
createUser("groupessai","useressai1","pass","rerfqze","dfsdfd");  //this include a call to groupessai.addUser(useressai1)
addUserToGroup("group1","useressai1");
addUserToGroup("group2","useressai1");
createUser("groupessai","useressai2","pass","rerfqze","dfsdfd");  //this include a call to groupessai.addUser(useressai2)
createUser("groupessai","useressai3","pass","rerfqze","dfsdfd");  //this include a call to groupessai.addUser(useressai3)
Here is the result in the association table :
uid gid i j
useressai1 groupessai NULL 0
useressai1 group1 0 NULL
useressai1 group2 0 NULL
useressai2 groupessai NULL 0
useressai3 groupessai NULL 0
So the question is does hibernate allow to have such a configuration and if yes how have I to do in order to make it work.
Thanks in advance for possible response.
Vlad