You probably get a new Database object in your delete() method,
right ? If so, the new db will not know about your totoBean =>
ObjectNotPersistent.
What happens if you just use db.remove(totoBean) ?
I had to implement a ThreadLocal object to keep the db objects
to avoid this problem in a facade above Castor I coded for one of my
clients.
Another (not so clean) solution would be to pass the db object to each method.
Cdrick Laballery wrote:
I'm meeting a problem with the following code:
<========== example ==========>
<assume ctx is a valid initial context>
UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
// begin the transaction
ut.begin();
JDO jdo = (JDO) ctx.lookup("java:comp/jdo/myJdo");
Database db = jdo.getDatabase();
OQLQuery oql = db.getOQLQuery("select b from test.TotoBean b");
QueryResults results = oql.execute();
while (results.hasMore()) {
totoBean = (TotoBean)results.next();
log.debug(totoBean.toString());
}
// delete the last found bean
totoBean.delete(); ==> raises an exception
ut.commit();
db.close();
<========== end of example ==========>
totoBean.delete() causes a ObjectNotPersistentException:
org.exolab.castor.jdo.ObjectNotPersistentException: The object of type test.TotoBean is not persistent -- it was not queried or created within this transaction
The fact is that this object has obviously been created within the transaction...
===> What's wrong with my code ?
===> One more thing: if I begin the transaction *after* getting the database, the call to oql.execute() raises a TransactionNotInProgressException. Is it normal ?
Thanks in advance for your help.
Cedrick
_________________________________________________________________
MSN Search, le moteur de recherche qui pense comme vous ! http://search.msn.fr/worldwide.asp
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
--
Mickael Guessant
Technical Consultant
http://mguessan.free.fr
mailto:[EMAIL PROTECTED]
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
