Hi Thomas,
thank you very much for your prompt response.
I've tried to put this very line before the commit of transaction, and
the error is not given any more, but the id of bean2 still can't be
got.(id = 0 got )
Object oid = pm.getObjectId(bean);
Department bean2 = (Department) pm.getObjectById(oid, true);
id = bean2.getId();
pm.currentTransaction().commit();
And, i m starting to think that my configuration of "autroincrement" has
a problem. In fact, i can only configure to use autoincrement in
datastore(Mysql), if i add {autoincrement="true"} in repository.xml, my
program can't work, that's to say, the new obj can't even be created
with error "Can not init Identity for given object". Do you think it
might be the reason for (id=0) that JDO is not aware of the
autoincremented ID? what can i do then?
Thank you very much, Phil
On Tue, 2004-04-13 at 13:57, Thomas Mahler wrote:
> Hi Philippe,
>
> Please try to obtain the OID before committing the transaction:
>
> Object oid = pm.getObjectId(bean);
> pm.currentTransaction().commit();
>
> The error message indicates that the JDO engine complains about a
> non-open (in your case already committed) transaction.
>
> cu,
> Thomas
>
> Philippe Guillard wrote:
> > Hi,
> >
> > I wanna create a new data object in datastore without precising the
> > primary id, while letting database naming the id autoincremently. But in
> > the same time, i need to know the id attributed to this object, so that
> > i can reuse it later.
> > I wrote the code in an xsp like following, but i
> > got an error saying :
> > "org.apache.cocoon.ProcessingException: Exception in
> > ServerPagesGenerator.generate(): javax.jdo.JDOUserException: No
> > transaction in progress."
> > (If i only execute the lines before Object oid = pm.getObjectId(bean);
> > the object is created successfully in the DB with an id incrementally. )
> >
> > Any idee? Another solution?
> >
> > thanks,
> >
> > Phil
> >
> > *******
> > <?xml version="1.0"?>
> > <xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
> >
> > <xsp:structure> // import class
> > <xsp:include>javax.jdo.PersistenceManager</xsp:include>
> > <xsp:include>javax.jdo.Transaction</xsp:include>
> >
> > <xsp:include>org.apache.cocoon.ojb.jdo.components.JdoPMF</xsp:include>
> > <xsp:include>javax.jdo.Transaction</xsp:include>
> >
> > <xsp:include>org.apache.cocoon.ojb.samples.bean.Department</xsp:include>
> > </xsp:structure>
> >
> > <xsp:init-page> // declare
> > JdoPMF pmf = null;
> > PersistenceManager pm = null;
> > PersistenceManager pm2 = null;
> > int id;
> > </xsp:init-page>
> >
> > <page>
> > <content>
> > <xsp:logic>
> > try {
> > /* Get the PersistenceManager */
> > try {
> > pmf = (JdoPMF) manager.lookup(JdoPMF.ROLE);
> > pm = pmf.getPersistenceManager();
> > } catch (ComponentException cme) {
> > getLogger().error("Could not look up the
> > PersistenceManager", cme);
> > }
> > pm.currentTransaction().begin();
> > Department bean = new Department();
> > bean.setName("JDO Development");
> > pm.makePersistent(bean); // add obj
> > in datastore
> > pm.currentTransaction().commit();
> >
> > Object oid = pm.getObjectId(bean); //
> > getObjectId of the identity object
> > pm.close();
> > pm2 = pmf.getPersistenceManager();
> > pm2.currentTransaction().begin();
> > Department bean2 = (Department) pm.getObjectById(oid,
> > true);
> > id = bean2.getId();
> >
> > </xsp:logic>
> > <p> Inserted data: <xsp:expr>id</xsp:expr></p>
> > <xsp:logic>
> > }
> > finally {
> > manager.release((Component)pmf);
> > }
> > </xsp:logic>
> > </content>
> > </page>
> > </xsp:page>
> >
> >
> > ---------------------------------------------------------------------
> > 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]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]