this isn't a cache problem. The CCE is caused by line
result = (ManageableCollection) collectionClass.newInstance();
All specified collection classes must implement interface ManageableCollection, more see
http://db.apache.org/ojb/tutorial3.html#Types%20Allowed%20for%20Implementing%201:n%20Associations
So change in your collection-descriptor
> <collection-descriptor > name="items" > element-class-ref="Item"
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
or ManageableVector or don't set this attribute, then OJB use an removal aware collection (objects removed from the collection will be ). Have a lok in ..broker.util.collections package.
regards, Armin
> auto-retrieve="true" > auto-update="false" > auto-delete="false" > otm-dependent="true" > refresh="true" > > > <inverse-foreignkey field-ref="locationID"/> > </collection-descriptor>
Georg Klima wrote:
Hello!
I don't know what I do wrong?
Tried all the tutorials, they work, use the "same" hsqldb as in the tutorials (earlier tried with mysql).
<jdbc-connection-descriptor jcd-alias="default" default-connection="true" platform="hsqldb" jdbc-level="2.0" driver="org.hsqldb.jdbcDriver" protocol="jdbc" subprotocol="hsqldb:hsql" dbalias="//localhost" username="ojb" password="ojb" eager-release="false" batch-mode="false" useAutoCommit="1" ignoreAutoCommitExceptions="false" >
<object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl"> <attribute attribute-name="attr_con" attribute-value="555"/> </object-cache>
<connection-pool maxActive="5" whenExhaustedAction="0" validationQuery="select count(*) from OJB_HL_SEQ" />
<sequence-manager className="org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl"> <attribute attribute-name="grabSize" attribute-value="5"/> </sequence-manager>
</jdbc-connection-descriptor>
And I always get this after I inserted a "Person" object into the Database and then quering with a "Template". (Quite similar to the tutorial)
java.lang.ClassCastException at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryRe ferenceBroker.java:102) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryRe ferenceBroker.java:203) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollection(QueryRefe renceBroker.java:498) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollections(QueryRef erenceBroker.java:656) at org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(RsIterat or.java:471) at org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:265) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByQuery(Persistenc eBrokerImpl.java:1449) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Dele gatingPersistenceBroker.java:300)
at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Dele gatingPersistenceBroker.java:300)
at Datenbank.findByTemplate(Unknown Source) at Main.main(Unknown Source) java.lang.ClassCastException org.apache.ojb.broker.PersistenceBrokerException: java.lang.ClassCastException at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryRe ferenceBroker.java:211) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollection(QueryRefe renceBroker.java:498) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollections(QueryRef erenceBroker.java:656) at org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(RsIterat or.java:471) at org.apache.ojb.broker.accesslayer.RsIterator.next(RsIterator.java:265) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByQuery(Persistenc eBrokerImpl.java:1449) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Dele gatingPersistenceBroker.java:300)
at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Dele gatingPersistenceBroker.java:300)
at Datenbank.findByTemplate(Unknown Source) at Main.main(Unknown Source) Caused by: java.lang.ClassCastException at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryRe ferenceBroker.java:102) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(QueryRe ferenceBroker.java:203) ... 9 more [org.apache.ojb.broker.cache.InternalCache] ERROR: Found 1 abandoned objects in local cache, check code to force push to real ObjectCache Exception in thread "main" java.lang.NullPointerException at Main.main(Unknown Source)
But the Person object is stored properly into the DB. And in the repository it defined that for caching <object-cache class="org.apache.ojb.broker.cache.ObjectCacheEmptyImpl"> <attribute attribute-name="attr_con" attribute-value="555"/> </object-cache>
(I also tried with the default cache implementation, but the same error)
my mapping: <class-descriptor
class="Person" table="PERSON" > <field-descriptor name="personID" column="PERSON_ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true" />
<field-descriptor name="name" column="NAME" jdbc-type="VARCHAR" />
<field-descriptor name="fines" column="FINES" jdbc-type="FLOAT" />
<collection-descriptor name="items" element-class-ref="Item" collection-class="java.util.Vector" auto-retrieve="true" auto-update="false" auto-delete="false" otm-dependent="true" refresh="true" > <inverse-foreignkey field-ref="locationID"/> </collection-descriptor>
</class-descriptor>
<class-descriptor
class="Item" table="ITEM" >
<field-descriptor name="itemID" column="ITEM_ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true" />
<field-descriptor name="title" column="TITLE" jdbc-type="VARCHAR" />
<field-descriptor name="author" column="AUTHOR" jdbc-type="VARCHAR" />
<field-descriptor name="isbn" column="ISBN" jdbc-type="INTEGER" />
<field-descriptor name="year" column="YEAR" jdbc-type="INTEGER" />
<field-descriptor name="locationID" column="LOCATION_ID" jdbc-type="INTEGER" />
<field-descriptor name="available" column="AVAILABLE" jdbc-type="BIT" />
<!-- <reference-descriptor name="location" class-ref="Person" auto-retrieve="true" auto-update="false" auto-delete="false" otm-dependent="true" refresh="true" proxy="true" > <foreignkey field-ref="locationID"/> </reference-descriptor> --> </class-descriptor>
my classes:
public class Person{
private Integer personID; private String name; private Double fines; private Vector items;
public Person(){}
public Person(String n, double f){ name=n; fines=new Double(f); }
public Person(String n, Double f){ name=n; fines=f; }
public void setName(String name){ this.name=name; }
public String getName(){ return name; }
public void setFine(double fines){ this.fines=new Double(fines); }
public double getFine(){ return fines.doubleValue(); }
public void addItem(Item i){ // if(items == null) // items = new Vector(); items.add(i); }
public void removeItem(Item i){ //if(items!=null) items.remove(i); }
public void removeItemAt(int i){ //if(items!=null) items.removeElementAt(i); }
public String toString(){ return personID + " | " + name + " | " + fines + " | " + items.toString(); } }
public class Item{ // extends InventoryEntry{
private Integer itemID; private String title; private String author; private Integer isbn; private Integer locationID; //private Person location; private Boolean available; private Integer year;
public Item(){}
public Item(String title, String author, int isbn, boolean available, int year){ this.title=title; this.author=author; setISBN(isbn); setAvailable(available); setYear(year); }
public Item(String title, String author, Integer isbn, Boolean available, Integer year){ this.title=title; this.author=author; this.isbn=isbn; this.available=available; this.year=year; }
public void setTitle(String title){ this.title=title; }
public String getTitle(){ return title; }
public void setISBN(int isbn){ this.isbn=new Integer(isbn); }
public int getISBN(){ return isbn.intValue(); } public void setYear(int y){ year=new Integer(y); } public int getYear(){ return year.intValue(); }
public void setAvailable(boolean b){ available=new Boolean(b); }
public boolean getAvailable(){ return available.booleanValue(); }
public String getAuthor(){ return author; }
public void setAuthor(String a){ author=a; }
public String toString(){ return itemID + " | " + title + " | " + isbn + " | " + locationID; }
public boolean equals(Item i){ return((new String(title + isbn + author + year)).equals(new String(i.getTitle() + i.getISBN() + i.getAuthor() + i.getYear()))); } }
Main appl (abstract):
Person p = new Person("Georg Klima", 0); Person o2 = (Person)db.findByTemplate(new Person("Georg Klima",null)); System.out.println(o2.toString());
Database appl (abstract): odmg = OJB.getInstance(); db = odmg.newDatabase(); db.open("default", Database.OPEN_READ_WRITE);
public void storeObject(Object o){ try{ Transaction tx = odmg.newTransaction(); tx.begin(); tx.lock(o, Transaction.WRITE); tx.commit(); }catch(Exception e){ System.out.println(e.getMessage()); e.printStackTrace(); } }
public Object findByTemplate(Object template){ PersistenceBroker broker = null; Object result = null; try{ broker = PersistenceBrokerFactory.defaultPersistenceBroker(); QueryByCriteria query = new QueryByCriteria(template); result = broker.getObjectByQuery(query); }catch(Exception e){ System.out.println(e.getMessage()); e.printStackTrace(); }finally{ if (broker != null) broker.close(); } return result; }
So what have I forgotten to do that has been done with the tutorial setup?
Thanks in advance! Georg Klima (a poor student seeking for help!)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]