-->
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.  [ 3 posts ] 
Author Message
 Post subject: Many-to-Many association fails to persist associative entity
PostPosted: Mon Oct 06, 2003 10:57 am 
Newbie

Joined: Mon Oct 06, 2003 10:09 am
Posts: 3
In my many-to-many association all data relating to the SystemUser is persisted correctly. But no record is added the intermediate table (NM_SYSTEM_USER_ROLE). I've scanned the log for INSERT statements and hibernate doesn't attempt to insert a record into the NM_SYSTEM_USER_ROLE table.

Interestingly when I retrieve the added SystemUser, the SELECT statement DOES contain the necessary join.

Regarding code - In my unit test is really simple, I open a Session and retrieve all of the roles, close the session, and add a couple of Role instances to a newly instantiated SystemUser, and set all of the other necessary beans properties. So the SystemUser id is null, but the Role.ids are set.

And then I open a new session, call session.saveOrUpdate(systemUser), followed by session.flush() and session.close().

I've been struggling with this for a couple of days now, so any help is much appreciated.

Here's the mapping for SystemUser.
    <class
    name="com.myemployer.myproject.domain.SystemUser"
    table="NM_SYSTEM_USER"
    dynamic-update="false"
    dynamic-insert="false"
    >

    <id
    name="id"
    column="id"
    type="java.lang.String"
    >
    <generator class="uuid.hex">
    </generator>
    </id>

    <many-to-one
    name="contactDetails"
    class="com.myemployer.myproject.domain.ContactDetails"
    cascade="save-update"
    outer-join="auto"
    update="true"
    insert="true"
    column="contact_details_fk"
    not-null="true"
    />

    <set
    name="roles"
    table="NM_SYSTEM_USER_ROLE"
    lazy="false"
    inverse="true"
    cascade="all"
    sort="unsorted"
    >

    <key
    column="system_user_id"
    />

    <many-to-many
    class="com.myemployer.myproject.domain.Role"
    column="role_id"
    outer-join="auto"
    />

    </set>

    <many-to-one
    name="login"
    class="com.myemployer.myproject.domain.Login"
    cascade="all"
    outer-join="auto"
    update="true"
    insert="true"
    column="login_fk"
    not-null="true"
    />

    <many-to-one
    name="status"
    class="com.myemployer.myproject.domain.Status"
    cascade="none"
    outer-join="auto"
    update="true"
    insert="true"
    column="status_fk"
    not-null="true"
    />

    <property
    name="lastModifier"
    type="java.lang.String"
    update="true"
    insert="true"
    column="lastModifier"
    not-null="true"
    />

    </class>


Here's the mapping for Role.
    <class
    name="com.myemployer.myproject.domain.Role"
    table="NM_ROLE"
    dynamic-update="false"
    dynamic-insert="false"
    >

    <id
    name="id"
    column="id"
    type="java.lang.String"
    >
    <generator class="uuid.hex">
    </generator>
    </id>

    <property
    name="name"
    type="java.lang.String"
    update="true"
    insert="true"
    column="name"
    not-null="true"
    />

    <property
    name="lastModifier"
    type="java.lang.String"
    update="true"
    insert="true"
    column="lastModifier"
    not-null="true"
    />

    </class>

The SQL used to create the relevant tables:
    create table NM_SYSTEM_USER (
    id VARCHAR2(255) not null,
    contact_details_fk VARCHAR2(255) not null,
    login_fk VARCHAR2(255) not null,
    status_fk VARCHAR2(255) not null,
    lastModifier VARCHAR2(255) not null,
    primary key (id)
    );
    create table NM_ROLE (
    id VARCHAR2(255) not null,
    name VARCHAR2(255) not null,
    lastModifier VARCHAR2(255) not null,
    primary key (id)
    );
    create table NM_SYSTEM_USER_ROLE (
    system_user_id VARCHAR2(255) not null,
    role_id VARCHAR2(255) not null,
    primary key (system_user_id, role_id)
    );


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 2:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use inverse="false", since it is unidirectional.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 5:55 am 
Newbie

Joined: Mon Oct 06, 2003 10:09 am
Posts: 3
fixed.
thnx.


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

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.