Hi,
I have a slight problem with a Castor program I am writing, involving an
object model that has relations two levels deep.
e.g.
User - 1..* - Document - 1..* - Audit
Now, I am able to create and commit User and Document objects in my
database. When creating a document, I create a bi-directional relation,
via the mapping file and the user's primary key is inserted in the
Document table. The User's primary key is user defined to reflect UNIX
user names.
(1) Create User and commit
(2) -Read user,
-Create Document,
-add User to Doc,
-add Doc to User collection (Long transaction)
The problem comes when creating an Audit object and commiting it to the
database. I pass a Document to the Audit object, however, when it
attempts to commit to the database, the primary key of the Document is
NULL. I have specified this to be a not null attribute to ensure that
every Audit has a Document. The Document key is an auto-generated UUID.
(1) Read User
(2) Read Document
(3) -Create Audit
-add User (works)
-add Doc (fails - SQL non null attribute exception)
-add Audit to Doc collection - never reaches
The closest reference I can find to my problem can be found at
http://www.mail-archive.com/[EMAIL PROTECTED]/msg07534.html. It
seems that this may have something to do with the key-generator,
however, I do not know enough to confirm.
I have added an edited copy of my mapping.xml file:
<mapping>
<class name="provenance.User" identity="UserName">
<map-to table="users"/>
<field name="UserName" type="string" required="true">
<sql name="user_name" type="varchar" />
</field>
....
<field name="Documents" type="provenance.Document"
collection="collection" lazy="true">
<sql many-key="author" />
</field>
</class>
<class name="provenance.Document" identity="DocID" key-generator="UUID">
<map-to table="document" />
<field name="DocID" type="string" required="true">
<sql name="doc_id" type="varchar"/>
</field>
...
<field name="Audits" type="provenance.Audit" collection="collection">
<sql many-key="document" />
</field>
<field name="user" type="provenance.User" required="true">
<sql name="author" />
</field>
</class>
<class name="provenance.Audit" identity="AuditID" key-generator="UUID" >
<map-to table="audit" />
<field name="AuditID" type="string" required="true">
<sql name="audit_id" type="varchar"/>
<bind-xml name="AuditID" node="element" />
</field>
....
<field name="document" type="provenance.Document" required="true">
<sql name="document" />
</field>
<field name="supersede" type="provenance.Document"
set-method="setSupersede"
get-method="getSupersede">
<sql name="supersedes" />
</field>
<field name="superseder" type="provenance.Document">
<sql name="superseder" />
</field>
<field name="auditor" type="provenance.User" required="true">
<sql name="auditor" />
</field>
</class>
</mapping>
Best Regards,
Rowland Watkins
Declarative Systems and Software Engineering Research Group
School of Electronics & Computer Science,
University of Southampton
UK
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev