Sam,
the first OQL query statement should read
OQLQuery query = db.getOQLQuery("select s
from Shop s where id=$1");
Werner
On Tue, 7 Oct 2003 23:29:19 -0700 (PDT), sam sam wrote:
>Hi,
>I am facing one problem while running one sample
>program.
>I didnt understand exactly where the problem is ?
>I am getting this error.
>Exception :org.exolab.castor.jdo.PersistenceException:
>non persistence capable: Shop
>Exception : org.exolab.castor.jdo.QueryException:
>Could not find class shops
>
>
>Can anyone please help me. Below is the code.
>Thanks & Rgds
>Sam
>
>Table shops
>create table shops(
>oid varchar(200) unique not null, name varchar(200),
>address varchar(200));
>
>
>Shop.java
>
>public class Shop {
> private String id;
> private String _Name;
> private String _Address;
> public String getId() {return id;}
> public void setId(String _id) {this.id = _id;}
> public String get_Name() {return _Name;}
> public void set_Name(String _Name) {this._Name =
>_Name;}
> public String get_Address() {return _Address;}
> public void set_Address(String _Address)
>{this._Address = _Address;}
>}
>******************************************************
>Shoptest.java
>
>import org.exolab.castor.jdo.*;
>import org.exolab.castor.jdo.JDO;
>import org.exolab.castor.util.Logger;
>import org.exolab.castor.mapping.*;
>import org.exolab.castor.builder.SourceGenerator;
>import java.util.*;
>
>import java.io.PrintWriter;
>
>public class Shoptest {
> public static void main(String[] args) {
> Shop _shop = new Shop();
>
> _shop.setId("0000001");
> _shop.set_Name("Testshop");
> _shop.set_Address("XXXXXXXXXXXX");
> System.out.println("Object : "+_shop.toString());
> // load database config
> try {
> JDO.loadConfiguration( "database.xml" );
> }catch (MappingException e) {
> System.out.println("Exception: "+e);
> }
> JDO jdo;
> Database db;
> jdo = new JDO( "test" );
> System.out.println(jdo.getDatabaseName());
> // try to save object
> try {
> db = jdo.getDatabase();
> db.begin();
> db.create(_shop);
> db.commit();
> db.close();
> }catch (PersistenceException e) {
> System.out.println("Exception : "+e);
> }
> // now retrieve object, change it and store
>the change
> try {
> db = jdo.getDatabase();
> db.begin();
> OQLQuery query = db.getOQLQuery("SELECT s
>FROM shops s WHERE id=$1");
> query.bind("0000001");
> QueryResults results = query.execute();
> System.out.println(results.size());
> Shop myShop = (Shop)results.next();
> System.out.println("NAME
>:"+myShop.get_Name());
> myShop.set_Name("new Shop");
> System.out.println("NEW NAME
>:"+myShop.get_Name());
> db.commit();
> db.close();
> }catch (PersistenceException e) {
> System.out.println("Exception : "+e);
> }
> }
>}
>******************************************************
>database.xml
>
><!DOCTYPE database PUBLIC "-//EXOLAB/Castor JDO
>Configuration DTD Version 1.0//EN"
>"http://castor.exolab.org/jdo-conf.dtd">
>
><database name="test" engine="oracle" >
> <driver
>url=""COLOR">"
>class-name="oracle.jdbc.driver.OracleDriver">
> <param name="user" value="test" />
> <param name="password" value="test" />
> </driver>
> <mapping href="" />
></database>
>******************************************************
>shop-mapping.xml
>
><?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="Shop" identity="id"
>key-generator="SEQUENCE">
> <map-to table="shops"/>
> <field name="id" type="string">
> <sql name="oid" type="char" />
> </field>
> <field name="_Name" type="string">
> <sql name="name" type="char" />
> </field>
> <field name="_Address" type="string">
> <sql name="address" type="char" />
> </field>
> </class>
></mapping>
>
>
>Note: forwarded message attached.
>
>
>__________________________________
>Do you Yahoo!?
>The New Yahoo! Shopping - with improved product search
>http://shopping.yahoo.com
