Seems to be a buf in my code... > -----Original Message----- > From: Sebastian Thomschke [mailto:[EMAIL PROTECTED] > Sent: Thursday, February 27, 2003 9:44 PM > To: [EMAIL PROTECTED] > Subject: OJB - JDO - deletePersistent > > > The JDO tutorial uses the pm.getObjectById() method to get an > instance of a > product to delete it. Shouldn't it be possible to do the same via > pm.newQuery? > In my JDO test project I first tried it using the > pm.newQuery() method to > get a user object/record. Retrieving was fine, but when I try > to delete it, > OJB throws the following exception: > javax.jdo.JDOUserException: Instance of class > sebthom.jdotest.persistenceObjects.User is not > persistent. > at > com.sun.jdori.common.PersistenceManagerImpl.deletePersistentIn > ternal(PersistenceManagerImpl.java:1823) > at > com.sun.jdori.common.PersistenceManagerImpl.deletePersistent(P > ersistenceManagerImpl.java:739) > at > com.sun.jdori.common.PersistenceManagerWrapper.deletePersisten > t(PersistenceManagerWrapper.java:444) > at sebthom.jdotest.Main.run(Main.java:120) > at sebthom.jdotest.Main.main(Main.java:165) > Exception in thread "main" > > When I use the pm.getObjectById() method it works fine. > What's wrong with > the way using pm.newQuery()? > > Thanks in advance. > > Regards, > Sebastian > > ====================================================== > > // Version 1 using pm.newQuery() > tx = pm.currentTransaction(); > tx.begin(); > query = pm.newQuery(User.class, "id==" + 10); > result = (Collection) query.execute(); > user = (User) result.iterator().next(); > if (user == null) > { > System.out.println("did not find a matching instance..."); > tx.rollback(); > } > else > { > pm.deletePersistent(user); > tx.commit(); > query.close(result); > } > > //Version 2 using pm.getObjectById() > User example = new User(); > example.setId(10); > Identity oid = new Identity(example); > User toBeDeleted = (User) pm.getObjectById(oid, false); > > tx = pm.currentTransaction(); > tx.begin(); > pm.deletePersistent(toBeDeleted); > if (toBeDeleted == null) > { > System.out.println("did not find a matching instance..."); > tx.rollback(); > } > else > { > pm.deletePersistent(toBeDeleted); > tx.commit(); > } > > -- > +++ GMX - Mail, Messaging & more http://www.gmx.net +++ > Bitte l�cheln! Fotogalerie online mit GMX ohne eigene Homepage! > > > > -- > +++ GMX - Mail, Messaging & more http://www.gmx.net +++ > Bitte l�cheln! Fotogalerie online mit GMX ohne eigene Homepage! > > > --------------------------------------------------------------------- > 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]
