Hi,
I got this exception when I am trying the code. It
works for the invoice table if I remove
db.create(method) line but that way method table will
be empty. The code and mapping file are attached.
org.exolab.castor.jdo.PersistenceException: Nested
error: java.sql.SQLException: ERROR: Relation
'method' does not exist
java.sql.SQLException: ERROR: Relation 'method' does
not exist
I would really appreciate any help i can get.
best regards
Sayed Fadhil
__________________________________________________
Do You Yahoo!?
Yahoo! Mobile - Jazz up your mobile phone! Get funky ringtones and logos!
http://mobile.yahoo.com.sg/
import java.io.*;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Date;
//import java.sql.Time;
import java.util.Enumeration;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.Serializable;
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.JDO;
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.OQLQuery;
import org.exolab.castor.jdo.QueryResults;
import org.exolab.castor.util.Logger;
import org.exolab.castor.xml.ClassDescriptorResolver;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.util.ClassDescriptorResolverImpl;
import org.exolab.castor.mapping.Mapping;
import org.apache.xml.serialize.*;
import test.*;
//import org.exolab.castor.types.Duration;
//import org.exolab.castor.types.Date;
//import org.exolab.castor.types.Time;
public class InvoiceTest {
//public static final String DatabaseFile = "database.xml";
//public static final String MappingFile = "map.xml";
private Mapping _mapping;
private JDO _jdo;
public static void main(String[] args) {
PrintWriter writer;
InvoiceTest test;
writer = new Logger( System.out).setPrefix("test");
try{
test = new InvoiceTest(writer);
test.run(writer);
}catch ( Exception except ) {
writer.println( except );
except.printStackTrace( writer );
}
}
public InvoiceTest ( PrintWriter writer ){}
public void run( PrintWriter writer )
throws Exception
{
Database db;
OQLQuery invoiceOql;
OQLQuery methodOql;
QueryResults results;
Invoice invoice = null;
writer.println("Unmarshalling Invoice");
invoice = Invoice.unmarshal(new FileReader("invoice_min.xml"));
writer.println();
writer.println("unmarshalled...performing tests...");
writer.println();
//-- Display unmarshalled address to the screen
writer.println("Invoice");
writer.println("-------");
writer.println();
writer.println("Ship To:");
String name = invoice.getName();
String id = invoice.getId();
writer.println(" " + id);
writer.println(" " + name);
writer.println();
writer.println("Shipping Method:");
ShippingMethod method = invoice.getShippingMethod();
int methodid =method.getId();
String option=method.getOption();
String carrier=method.getCarrier();
writer.println(" " + methodid);
writer.println(" " + carrier);
writer.println(" " + option);
writer.println();
writer.println("Shipping Date:");
String date = invoice.getShippingDate();
writer.println(" Date :"+date);
//writer.println(" Date :"+date.toString());
writer.println();
writer.println("----End of Invoice----");
// invoice.marshal(new FileWriter("invoice2.xml"));
_jdo = new JDO();
_jdo.setLogWriter( writer );
_jdo.setConfiguration( getClass().getResource( "database1.xml" ).toString() );
_jdo.setDatabaseName( "invoicetest" );
writer.println("JDO open");
// Load the mapping file
_mapping = new Mapping( getClass().getClassLoader() );
_mapping.setLogWriter( writer );
_mapping.loadMapping( getClass().getResource( "map1.xml" ) );
writer.println("mapping configured");
db = _jdo.getDatabase();
writer.println("JDO Configured.");
db.begin();
writer.println( "Begin transaction" );
//invoiceOql.bind( 3 );
//results = invoiceOql.execute();
//if ( ! results.hasMore() ) {
method = new ShippingMethod();
method.setId(methodid);
method.setOption(option);
method.setCarrier(carrier);
db.create(method);
invoice = new Invoice();
invoice.setId( id );
invoice.setName( name );
invoice.setShippingMethod(method);
invoice.setShippingDate( date);
db.create( invoice );
writer.println( "Creating new invoice: " );
//} else {
// invoice = (Invoice) results.next();
// writer.println( "Query result: " + invoice );
// }
db.commit();
db.close();
}
}
<?xml version="1.0"?>
<mapping xmlns="http://castor.exolab.org/" xmlns:cst="http://castor.exolab.org/">
<description>Castor generated mapping file</description>
<class cst:name="test.Invoice" identity="id">
<description>Default mapping for class test.Invoice</description>
<map-to cst:table="invoice" cst:xml="invoice" />
<field cst:name="id" cst:type="string" cst:required="true">
<sql cst:name="id" cst:type="varchar" />
<xml cst:name="id" cst:node="attribute"/>
</field>
<field cst:name="name" cst:type="string" >
<sql cst:name="name" cst:type="varchar" />
<xml cst:name="name" cst:node="element"/>
</field>
<field cst:name="shippingMethod" cst:type="test.ShippingMethod" >
<sql cst:name="method-id"/>
<xml cst:name="shipping-method" cst:node="element"/>
</field>
<field cst:name="shippingDate" cst:type="string" >
<sql cst:name="date" cst:type="varchar" />
<xml cst:name="shipping-date" cst:node="element"/>
</field>
<!--
<field cst:name="shippingTime" cst:type="java.util.Time" >
<sql cst:name="time" cst:type="time" />
<xml cst:name="shipping-time" cst:node="element"/>
</field>-->
</class>
<class cst:name="test.ShippingMethod" identity="id">
<description>Default mapping for class test.ShippingMethod</description>
<map-to cst:table="method" cst:xml="shipping-method" />
<field cst:name="id" cst:type="integer" cst:required="true">
<sql cst:name="id" cst:type="integer" />
<xml cst:name="id" cst:node="attribute"/>
</field>
<field cst:name="carrier" cst:type="string" >
<sql cst:name="carrier" cst:type="varchar"/>
<xml cst:name="carrier" cst:node="element"/>
</field>
<field cst:name="option" cst:type="string" >
<sql cst:name="option" cst:type="varchar"/>
<xml cst:name="option" cst:node="element"/>
</field>
</class>
</mapping>