Hi Eric,

Instead of using ids to maintain your object graph, try using object
references. This is castor's normal mode.

For instance, in MissionSchedulingRequest you would have methods like
these:

public void setOpLoc(OpLoc loc)
public OpLoc getOpLoc()

and so on. (If the relationship is 1:N, castor can deal with
collections, too.) Castor can abstract away the translation of these
objects to and from ids for storing and loading. There is some info in
the castor docs about this; see
http://castor.exolab.org/castor-one.html#Different-cardinalities-of-
relationship for instance.

Finally, the "depends" relationship is worthwhile if you never need to
access a particular object without its parent. It provides a way to
specify that a particular child object must always be loaded when its
parent is and cannot be loaded in isolation.

If this is unclear, please ask again.

Rhett
--
Rhett Sutphin
Research Assistant (Software)
Coordinated Laboratory for Computational Genomics
and the Center for Macular Degeneration
University of Iowa - Iowa City, IA 52242 - USA
4111 MEBRF - email: [EMAIL PROTECTED]

On Wednesday, January 29, 2003, at 10:39 PM, Eric Hunt wrote:
Thanks Bruce..here is the stack trace with one caveat..I took your
advice and removed the "use=required" entry from the OpLoc schema def.
That got the key generator working okay, but only to create the next
problem.
My Unit class references the OpLoc id field, such that when I store
Unit,
I am also storing the OpLoc id.� At least that is my intent.� And just
so you know,
The Aircraft class must store both OpLoc and Unit id's, so I can see
that problem coming next.

To clarify what I am trying to do, I am trying to store the Id's of
each parent
relationship in each respective child, to enable queries on this field
later.� My relationship
Hierarchy is as follows, from right to left (parent to child)

MissionSchedulingRequest - OpLoc - Unit - Aircraft

MissionSchedulingRequest - OpLoc - Muniton

MissionSchedulingRequest - Target - Weaponeering

Pardon the repetition.� As you can see, MisionSchedulingRequest is the
top level,
followed by OpLoc and Target.� Oploc is then the parent for Unit and
Munition and Target
is the parent for Weaponeering.� Finally, Unit is the parent for
Aircraft.

Granted, I may be anal about storing all these Id's, but I need to be
able to backtrack.
For example, once I have an Aircraft, I need to be able to trace it
back to its Unit, Operating Location,
and ultimately which MissionSchedulingRequest it came from.� If you
see a more elegant way to handle this
I am very open to suggestions.

One nugget I came across was the use of "depends", but I am not sure
this will solve my problem.

Without further ado, the stack trace

[msf] Begin transaction
Unmarshalling Mission Scheduling Request
[msf] Insert Mission Scheduling Request ...
[msf] Castor: Creating msf.MissionSchedulingRequest (1)
[msf] Insert OpLocs ...
OpLocList value = 0
[msf] Castor: Creating msf.OpLoc (null)
[msf] Insert unit FKs...
[msf] Castor: Creating msf.Unit (1)
[msf] Error creating msf.Unit, SQL : INSERT INTO "UNIT"
("ID","MSR_ID","OPLOC_ID","UNIT_NAME") VALUES (?,?,?,?)
[msf] org.exolab.castor.jdo.PersistenceException: Nested error:
java.sql.SQLException: ORA-01400: cannot insert NULL into
("MSF"."UNIT"."OPLOC_ID")

[msf] java.sql.SQLException: ORA-01400: cannot insert NULL into
("MSF"."UNIT"."OPLOC_ID")

[msf] � at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
[msf] � at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
[msf] � at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
[msf] � at
oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1451)
[msf] � at
oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:862)
[msf] � at
oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java
:1846)
[msf] � at
oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:
1771)
[msf] � at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement
.java:2361)
[msf] � at
oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePrepared
Statement.java:422)
[msf] � at org.exolab.castor.jdo.engine.SQLEngine.create(Unknown
Source)
[msf] � at org.exolab.castor.persist.ClassMolder.create(Unknown Source)
[msf] � at org.exolab.castor.persist.LockEngine.create(Unknown Source)
[msf] � at org.exolab.castor.persist.TransactionContext.create(Unknown
Source)
[msf] � at org.exolab.castor.jdo.engine.DatabaseImpl.create(Unknown
Source)
[msf] � at Msf.run(Unknown Source)
[msf] � at Msf.main(Unknown Source)

I inserted a output line to check the value of Oploc id when unit is
written.� The result is above in red.
Here is the code I'm using to unmarshal the document.� If it looks
familiar it is an adaptation of the unmarshaling
example I found at the ebXMSoft site.� Thanks for any help in advance.

import javax.sql.*;
import java.util.*;
import java.io.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.DriverManager;
import org.xml.sax.ContentHandler;
import org.exolab.castor.jdo.*;
import org.exolab.castor.util.*;
import org.exolab.castor.xml.*;
import org.exolab.castor.mapping.Mapping;
import org.apache.xml.serialize.*;
import msf.*;


public class Msf
{

��� // database configuration file
��� public static final String DatabaseFile = "database.xml";
��� // mapping file
��� public static final String MappingFile = "mapping.xml";

��� private Mapping� _mapping;

��� private JDO����� _jdo;

��� private MissionSchedulingRequest _missionSchedulingRequest;



��� public void Prepenv( PrintWriter writer )
������� throws Exception
��� {

������� // Load the mapping file
������� _mapping = new Mapping( getClass().getClassLoader() );
������� _mapping.setLogWriter( writer );
������� _mapping.loadMapping( getClass().getResource( MappingFile ) );

������� _jdo = new JDO();
������� _jdo.setLogWriter( writer );
������� _jdo.setConfiguration( getClass().getResource( DatabaseFile
).toString() );
������� _jdo.setDatabaseName( "webtas" );
��� }


��� public void run( PrintWriter writer )
������� throws Exception
��� {
������� Database����� � �������� db;
������� MissionSchedulingRequest missionSchedulingRequest;
������� OpLoc�� ������� ������� ������� ���� oploc;
������� Unit������������ ������ �������� unit;
������� Aircraft������� ������� ������� �������� aircraft;
������� Munition���������������� munition;
������� Target���� ���� ������������ target;
������� Weaponeering������������ weaponeering;
������� QueryResults������������ results;


������� db = _jdo.getDatabase();

������� writer.println( "Begin transaction" );

������� System.out.println("Unmarshalling Mission Scheduling Request");
������� _missionSchedulingRequest =
MissionSchedulingRequest.unmarshal(new
FileReader("request_trunc.xml"));

������� // Insert request
������� db.begin();
������� writer.println( "Insert Mission Scheduling Request ..." );
������� db.create(_missionSchedulingRequest);
������� db.commit();

������� // Insert Operating Locations (OpLocs)
������� OpLoc[] opLocList = _missionSchedulingRequest.getOpLoc();
������� ������� for (int g=0; g < opLocList.length; g++)
������� ������� {
������� ������� �� writer.println( "Insert OpLocs ...." );
������� ������� ��
opLocList[g].setMissionSchedulingRequest(_missionSchedulingRequest);
������� ������� �� System.out.println("OpLocList value = " +
opLocList[g].getId());
������� ������� �� db.begin();
������� ������� �� db.create(opLocList[g]);
���������� db.commit();

���������� writer.println( "Insert unit FKs..." );
������� ������� �� Unit[] unitList = opLocList[g].getUnit();
������� ������� �� for (int h=0; h < unitList.length; h++)
������� ������� �� {
������� ������� ����� OpLoc unitOpLoc = opLocList[g];
������� ������� ����� unitList[h].setOpLoc(unitOpLoc);
������� ������� �����
unitList[h].setMissionSchedulingRequest(_missionSchedulingRequest);
������� ������� ����� db.begin();
������� ������� ����� db.create(unitList[h]);
������� ������� ����� db.commit();

������� ������� ����� writer.println( "Insert aircraft FKs...");
������� ������� ����� Aircraft[] aircraftList =
unitList[h].getAircraft();
������� ������� ����� for (int a = 0; a < aircraftList.length; a++)
������� ������� ����� {
������� ������� ������� ������� � Unit aircraftUnit = unitList[h];
������� ������� ������� ������� �
aircraftList[a].setUnit(aircraftUnit);
������� ������� ������� ������� � aircraftList[a].setOpLoc(unitOpLoc);
������� ������� ������� ������� �
aircraftList[a].setMissionSchedulingRequest(_missionSchedulingRequest);
������� ������� ��������� db.begin();
������� ������� ������� ������� � db.create(aircraftList[a]);
������� ������� ������� ������� � db.commit();
������� ������� ������� � }

������� ������� �� }


���������� writer.println( "Insert munition FKs..." );
������� ������� �� Munition[] munitionList =
opLocList[g].getMunition();
������� ������� �� db.begin();
������� ������� �� for (int i=0; i < munitionList.length; i++)
������� ������� �� {
������� ������� ����� OpLoc munitionOpLoc = opLocList[g];
������� ������� ����� munitionList[i].setOpLoc(munitionOpLoc);
������� ������� �����
munitionList[i].setMissionSchedulingRequest(_missionSchedulingRequest);
������� ������� ����� db.create(munitionList[i]);
������� ������� �� }
���������� db.commit();
������� ��� }

������� ��� //Insert Units
������� ��� Unit[] unitList = _missionSchedulingRequest.getUnit();
������� ��� db.begin();
������� ������� for (int j=0; j < unitList.length; j++)
������� ������� {
������� ������� �� writer.println( "Insert Units ..." );
������� ������� �� db.create(unitList[j]);
������� ��� }
������� ��� db.commit();

������� ��� // Insert Aircraft
������� ������� Aircraft[] aircraftList =
_missionSchedulingRequest.getAircraft();
������� ������� db.begin();
������� ������� for (int m=0; m < aircraftList.length; m++)
������� ������� {
������� ������� �� writer.println( "Insert aircraft ...." );
������� ������� �� db.create(aircraftList[m]);
������� ������� }
������� ������� db.commit();

������� // Insert Munition
������� ������� Munition[] munitionList =
_missionSchedulingRequest.getMunition();
������� ������� db.begin();
������� ������� for (int n=0; n < munitionList.length; n++)
������� ������� {
������� ������� �� writer.println( "Insert munitions ...." );
������� ������� �� db.create(munitionList[n]);
������� ������� }
������� ������� db.commit();

������� // Insert Targets
������� Target[] tgtList = _missionSchedulingRequest.getTarget();
������� for (int p=0; p < tgtList.length; p++)
������� {
���������� writer.println( "Insert targets ..." );
����������
tgtList[p].setMissionSchedulingRequest(_missionSchedulingRequest);
���������� db.begin();
���������� db.create(tgtList[p]);
���������� db.commit();

���������� writer.println( "Insert target weaponeering FKs..." );
���������� Weaponeering[] weaponeeringList =
tgtList[p].getWeaponeering();
���������� db.begin();
���������� for (int q=0; q < weaponeeringList.length; q++)
���������� {
������������� Target weaponeeringTarget = tgtList[p];
������������� weaponeeringList[q].setTarget(weaponeeringTarget);
�������������
weaponeeringList[q].setMissionSchedulingRequest(_missionSchedulingReque
st);
������������� db.create(weaponeeringList[q]);
������� ������ }
���������� db.commit();
������� }

������� // Insert Weaponeering
������� Weaponeering[] weaponList =
_missionSchedulingRequest.getWeaponeering();
������� db.begin();
������� for (int r=0; r < weaponList.length; r++)
������� {
���������� writer.println( "Insert weaponeering ..." );
���������� db.create(weaponList[r]);
������� }
������� db.commit();
������� db.close();
��� }


��� public static void main( String[] args )
��� {
������� PrintWriter�� writer;
������� Msf msf = new Msf();

������� writer = new Logger( System.out ).setPrefix( "msf" );
������� try {
����������� msf.Prepenv( writer );
����������� msf.run( writer );
������� } catch ( Exception except ) {
����������� writer.println( except );
����������� except.printStackTrace( writer );
������� }
��� }


}

-----Original Message-----
From: Bruce Snyder [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 28, 2003 2:10 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Unable to generate key with key generator


This one time, at band camp, Eric Hunt said:

Please see my comments inline.

EH><!-- OpLoc -->
EH><xsd:element name="OpLoc">
EH>�� <xsd:complexType>
EH>����� <xsd:sequence>
EH>�������� <xsd:element����� ref="MissionSchedulingRequest"�
minOccurs="0"
EH>maxOccurs="1" />
EH>�������� <xsd:element����� ref="Unit"�� minOccurs="0"
EH>maxOccurs="unbounded" />
EH>�������� <xsd:element����� ref="Munition"� minOccurs="0"
EH>maxOccurs="unbounded" />
EH>�������� <xsd:element name="LocationName"����� type="xsd:string"
EH>minOccurs="0" maxOccurs="1" />
EH>�������� <xsd:element name="ICAO"������������������
type="xsd:string"
EH>minOccurs="0" maxOccurs="1" />�
EH>�������� <xsd:element name="Latitude"��������������
type="xsd:string"
EH>minOccurs="0" maxOccurs="1" />
EH>�������� <xsd:element name="Longitude"����������� type="xsd:string"
EH>minOccurs="0" maxOccurs="1" />
EH>�������� <xsd:element name="Elevation"������������
type="xsd:integer"
EH>minOccurs="0" maxOccurs="1" />���
EH>����� </xsd:sequence>
EH>����� <xsd:attribute name="id" type="xsd:integer" use="required"/>
���������������������������������������������������� ^^^^^^^^^^^^^ I'm
no XML expert (see the Castor XML guys for that) but it appears that
the attribute listed above states that the XML instance must have an
id populated in order to pass the validation test. Are you validating
the XML instance?

EH>The error I get is that I am missing my OpLoc id, probably since
EH>it doesn't appear in the data file.� I made the assumption that
EH>since it is being generated, I didn't need to reference the OpLoc
EH>id field in the xml unmarshalling doc.� Maybe a faulty assumption?.
EH>I tried using OpLoc id="" (an empty value), no luck. Obviously
EH>the key generator is not helping me much here, and I haven't found
EH>anything in the docs or samples that works.

What is the error, exactly? Please post the stack trace.

EH>Any ideas?� If I take out references to the key generator and
include
EH>id="1" and so forth, such that the OpLoc class entry in my xml doc
looks
EH>like this
EH><OpLoc id="1">, it works fine. However, this app would be much
easier to
EH>implement
EH>if I can generate my own keys.� Any help would be appreciated.

Bruce
--
perl -e 'print
unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

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


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

Reply via email to