Hi Werner,
Thanx 4 response.
I have modified few things but still its not able to
find the class. Its creating a new record in database
but not able read from there. Giving this error

Creating new shop: [EMAIL PROTECTED]
Exception : org.exolab.castor.jdo.QueryException:
Could not find mapping for class Shop


Shoptest.java

package com.test;

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 org.exolab.castor.persist.spi.Complex;
import java.util.*;

public class Shoptest {
    public static void main(String[] args) {
       
        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();
                        Shop _shop = new Shop("0000001","DVD","DVD");
            db.create(_shop);
                        System.out.println( "Creating new shop: " + _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  com.test.Shop 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);
        }
    }
}


shopping.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="com.test.Shop" identity="id">
      <map-to table="shops" xml="shops" />
      <field name="id" type="string">
        <sql name="oid" type="varchar"/>
        <bind-xml/>
      </field>
      <field name="_Name" type="string">
        <sql name="name" type="varchar"/>
        <bind-xml node="element" />
      </field>
           <field name="_Address" type="string">
       <sql name="address" type="varchar" />
           <bind-xml node="element"/>
       </field>
  </class>

</mapping>

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="jdbc:oracle:thin:@160.110.214.15:1521:sunlas"
class-name="oracle.jdbc.driver.OracleDriver">
         <param name="user" value="test" />
         <param name="password" value="test" />
    </driver>
  <mapping href="shop-mapping.xml" />
</database>

Can u tell me abt this problem.

Rgds
Sam



--- Werner Guttmann <[EMAIL PROTECTED]>
wrote:
> 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="jdbc:oracle:thin:@160.110.214.15:1521:test"
> >class-name="oracle.jdbc.driver.OracleDriver">
> >         <param name="user" value="test" />
> >         <param name="password" value="test" />
> >    </driver>
> >  <mapping href="shop-mapping.xml" />
> ></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
> 
> 
> 
> 
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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

Reply via email to