Yes, I´m interesting in retrive all the products from my table and I know that getCollectionByQuery returns a collection of instances that fit in the criteria of my query. Source is the next....
public class ProductAccessor { .......................... Iterator findAll(PersistenceBroker persistenceBroker) throws InternalErrorException { try { Query query = new QueryByCriteria(Product.class, null); ManageableCollection collection = persistenceBroker.getCollectionByQuery( Product.class, query); return collection.ojbIterator(); } catch (Exception e) { e.printStackTrace(); throw new InternalErrorException(e); } } .................................................. } ..and ...... Iterator iterator = productAccessor.findAll(persistenceBroker); while (iterator.hasNext()) System.out.println(((Product)iterator.next()).toString()); ...................... but when I execute it I get an exception of type ClassCastException. > > > >java.lang.ClassCastException: Product > > at > >org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQ > >uery(Unknown Source) > > at > >org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQ > >uery(Unknown Source) > > at > >org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQ > >uery(Unknown Source) > > at > >org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getCollect > >ionByQuery(Unknown Source) > > at ProductOJBDAO.findAll(ProductOJBDAO.java:13) > > at ProductAccessor.findAll(ProductAccessor.java:26) > > at ProductAccessor.main(ProductAccessor.java:77) > >InternalErrorException: Product > > at ProductAccessor.findAll(ProductAccessor.java:28) > > at ProductAccessor.main(ProductAccessor.java:77) > > > >Source of Product class is.... > > > >public class Product > > { > > /** > > * this is the primary key attribute needed by OJB to > > * identify instances > > */ > > private int id; > > > > public int getId() { > > return id; > > } > > > > public void setId(int id) { > > this.id = id; > > } > > > > /** product name*/ > > protected String name; > > /** price per item*/ > > protected int price; > > /** stock of currently available items*/ > > protected int stock; > > > > public Product() {} > > > > public String getName() { > > return this.name; > > } > > > > public void setName(String name) { > > this.name = name; > > } > > > > public int getPrice() { > > return this.price; > > } > > > > public void setPrice(int price) { > > this.price = price; > > } > > > > public int getStock() { > > return this.stock; > > } > > > > public void setStock(int stock) { > > this.stock = stock; > > } > > } > > > >and respositoy.xml asociated is.... > > > > > > <class-descriptor > > class="Product" > > table="product" > > sequence-manager=" > >org.apache.ojb.broker.util.sequence.SequenceManagerHiLoImpl" > > > > > <field-descriptor id="1" > > name="id" > > column="id" > > jdbc-type="INTEGER" > > primarykey="true" > > autoincrement="true" > > /> > > > > <field-descriptor id="2" > > name="name" > > column="name" > > jdbc-type="VARCHAR" > > /> > > <field-descriptor id="3" > > name="price" > > column="price" > > jdbc-type="INTEGER" > > /> > > <field-descriptor id="4" > > name="stock" > > column="stock" > > jdbc-type="INTEGER" > > /> > > </class-descriptor> > > > >.... but when I try to insert or delete a instance of product on my > >database, it's OK!!!! > > > >Any idea ?¿? > > > >Thanks in advanced and sorry for my poor english!!!! > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]