Hi-
I'm having a problem deleting an object from the database in
Castor 0.9.3. In the example below, I insert it, then delete
it right after. This fails on the line "db2.remove" line with the
stack trace below. However, if I comment out the
insertion code (so it only deletes an existing record from
a previous run) it works ok. Am I doing something wrong here?
Another bizarre thing is that if there is more than one record
that matches the delete statement, this works fine. I'm running
Postgres 7.1.
public static void main(String[] argv) {
JDO jdo=new JDO();
jdo.setDatabaseName(_database);
jdo.setConfiguration(_configfile);
PersonDAO pdao=null;
String login= "testdata";
// insert a record
Database db=null;
try {
db = jdo.getDatabase();
}
catch (Exception ex) {ex.printStackTrace(); System.exit(1);}
// create a new record
pdao=new PersonDAO();
pdao.setLogin(login);
try {
db.begin();
db.create(pdao);
db.commit();
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
finally {
try {db.close();} catch (Exception ex) {ex.printStackTrace();}
}
// now delete the record
Database db2=null;
try {
db2 = jdo.getDatabase();
}
catch (Exception ex) {ex.printStackTrace(); System.exit(1);}
try {
db2.begin();
OQLQuery personOql=db2.getOQLQuery("SELECT person FROM
com.bridgecanada.dao.PersonDAO person WHERE login=$1");
personOql.bind(login);
QueryResults results=personOql.execute();
while (results.hasMore()) {
pdao = (PersonDAO) results.next();
System.out.println("removing record "+pdao.getId()+")"+pdao.getLogin());
db2.remove(pdao);
System.out.println("OK");
}
System.out.println("Committing to db");
db2.commit();
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {db2.close();} catch (Exception ex) {ex.printStackTrace();}
}
}
Here's the stack trace:
removing record 5)testdata
java.lang.NullPointerException
at org.exolab.castor.persist.ClassMolder.markDelete(ClassMolder.java:2400)
at org.exolab.castor.persist.LockEngine.markDelete(LockEngine.java:548)
at
org.exolab.castor.persist.TransactionContext.delete(TransactionContext.java:895)
at org.exolab.castor.jdo.engine.DatabaseImpl.remove(DatabaseImpl.java:379)
at com.bridgecanada.session.RegisterSession.main(RegisterSession.java:219)
org.exolab.castor.jdo.PersistenceException: jdo.dbClosedTxRolledback
at java.lang.Throwable.<init>(Throwable.java:96)
at java.lang.Exception.<init>(Exception.java:44)
at
org.exolab.castor.jdo.PersistenceException.<init>(PersistenceException.java:79)
at org.exolab.castor.jdo.engine.DatabaseImpl.close(DatabaseImpl.java:247)
at com.bridgecanada.session.RegisterSession.main(RegisterSession.java:229)
--
Mike Bridge
<[EMAIL PROTECTED]>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev