Hi

I have two objects which have a one to many relation. I want to use JDO to map these objects to a DB and have defined a mapping file. This piece is working fine. Now I want to use castor xml to unmarshall an xml document to instantiate and load objects with data which then will be persisted in the DB using JDO feature. Unmarshalling is also working except that the object instantiated does not fullfill one to many relation constraint.

Objects: Comapny and UserInfo where company can point to many UserInfo (employee field in company object).

addEmployee() method in company object also set this relation for UserInfo(employee) object

public void addEmployee(UserInfo emp) {
  this.employee.addElement(emp);
  emp.setCompany(this);
}

Since this method is not invoked when Unmarshaller executes, this relation is not set for UserInfo(employee) and the foreign key field in 'user_info' table which needs a company id generates, java.sql.SQLException: ERROR: ExecInsert: Fail to add null value in not null attribute company_id.

How do I fix this problem.

thanks

Rav

Here is the mapping xml file:

<?xml version="1.0"?> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN" "http://castor.exolab.org/mapping.dtd";>
<mapping>
<class name="com.inventes.bobj.Company" key-generator="seqgen" identity="objectId">
<map-to xml="company" table="company" />
<field name="objectId" type="integer">
<sql name="id" type="integer"/>
<bind-xml name="objectId"/>
</field>
<field name="name" type="string">
<sql name="name" type="varchar"/>
<bind-xml name="name"/>
</field>
<field name="description" type="string">
<sql name="description" type="varchar"/>
<bind-xml name="description"/>
</field>
<field name="employee" type="com.inventes.bobj.UserInfo" collection="vector">
<sql many-key="company_id"/>
<bind-xml name="employee"/>
</field>
</class>
<class name="com.inventes.bobj.UserInfo" key-generator="seqgen" identity="objectId">
<map-to xml="employee" table="user_info"/>
<field name="objectId" type="integer">
<sql name="id" type="integer"/>
<bind-xml name="id"/>
</field>
<field name="firstName" type="string">
<sql name="first_name" type="varchar"/>
<bind-xml name="first-name"/>
</field>
<field name="lastName" type="string">
<sql name="last_name" type="varchar"/>
<bind-xml name="last-name"/>
</field>
<field name="company" type="com.inventes.bobj.Company">
<sql name="company_id"/>
<bind-xml name="company" reference="true"/>
</field>
</class>
<key-generator name="SEQUENCE" alias="seqgen">
<param name="sequence" value="{0}_{1}_seq"/>
</key-generator>
</mapping>
-------------------------------------------------------------------------------------------------
XML data file:


<?xml version="1.0" encoding="UTF-8"?>
<company>
        <employee>
                <last-name>xml emp lname 1</last-name>
                <first-name>xml emp fname 1</first-name>
        </employee>
        <employee>
                <last-name>xml emp lname 2</last-name>
                <first-name>xml emp fname 1</first-name>
        </employee>
        <name>xml company 1</name>
        <description>xml company 1 desc</description>
</company>

----------------------------------------------------------------------------------------------------------

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail


----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev




Reply via email to