I have a table of possible roles for users. There is a "to many"
relationship from users to roles. When I create a new user and add the roles
and save, I get a duplicate identity error for the role. The role should not
be saving since it already exits.
Both the User and Role object implement the TimeStampable interface. Also as
the subject implies, I am doing this as a long transaction.
I have also tried a suggestion I have seen in the mail archives to override
the jdoPersistent() method and make sure all related objects are updated in
the database object. I have also tried it without doing this.
Does anyone know what I am doing wrong? I have done some investigation and
the role does have the time stamp set and the database knows it is part of
the transaction.
Thanks
Frank
Pseudo code:
Database.begin();
Fetch possible roles
Database.commit();
// wait for the user
User = new User();
User.addRole(role);
Database.setAutoStore(true);
Database.begin()
Database.create(user);
Database.commit(); // Get a duplicate identity error for the role
Relevant Mapping:
<!-- Mapping for User -->
<class name="demo.persistent.User" identity="id"
key-generator="IDENTITY">
<map-to table="User"/>
<cache-type type="unlimited"/>
<field name="id" type="integer">
<sql name="id" type="integer"/>
</field>
<field name="firstName" type="string">
<sql name="first_name" type="char"/>
</field>
<field name="lastName" type="string">
<sql name="last_name" type="char"/>
</field>
<field name="login" type="string">
<sql name="login" type="char"/>
</field>
<field name="password" type="string">
<sql name="password" type="char"/>
</field>
<field name="roles" type="demo.persistent.Role"
collection="collection">
<sql many-table="User_To_Role" many-key="user_id"
name="role_id"/>
</field>
</class>
<!-- Mapping for Role -->
<class name="demo.persistent.Role" identity="id" access="read-only">
<map-to table="Role"/>
<cache-type type="unlimited"/>
<field name="id" type="integer">
<sql name="id" type="integer"/>
</field>
<field name="name" type="string">
<sql name="name" type="char"/>
</field>
<field name="longName" type="string">
<sql name="long_name" type="char"/>
</field>
</class>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev