Problem of persistence in JDO

7 views
Skip to first unread message

lisandro

unread,
Jul 22, 2010, 9:59:37 PM7/22/10
to Google App Engine
Hi! I have a problem with active transaction.When I try to guard in
the datastore, says:

"Object with id "com.google.appengine.api.datastore.Key:Torneo(1)/
Equipo(3)" is managed by a different Object Manager".
Similar problem happens in this link, but the solution indicated there
does not serve me:
http://stackoverflow.com/questions/1403515/appengine-datastore-object-with-id-is-managed-by-a-different-object-manager

Design:
A Torneo has relation one to many Equipo
A Fecha has relation one to many Partido

The method where one finds the mistake:
private static PersistenceManager pm =
PMF.get().getPersistenceManager();
//pm is a singleton
public void crearPartido(Long idEqLocal, Long idEqVisitante, Date
fecha,
Fecha fechaAgreg, String resultado, String
hora,Long idTorneo){

PersistenceManager pm =
JDOHelper.getPersistenceManager(fechaAgreg);
//or Transaction tx = pm.currentTransaction();
Transaction tx = pm.currentTransaction();

try {
tx.begin();
Partido par1 = null;
ControladorTorneo cT= new ControladorTorneo();
par1 = new Partido(null, new
Resultado(),cT.devolverEquipo( idTorneo,idEqLocal),
cT.devolverEquipo(idTorneo,idEqVisitante), fecha, hora);
/*In mode debug, is here below where accedes for the
block finally(with error) */
fechaAgreg.agregarPartido(par1);

pm.makePersistent(fechaAgreg);
tx.commit();

} finally {
if (tx != null && tx.isActive())
tx.rollback();
pm.close();
}

}

And the method crearPartido is called for:
public String execute() throws Exception {

ControladorFecha cF = new ControladorFecha();

Fecha fechaSel = cF.devolverFecha(fecha, torParam);
ControladorPartido cP= new ControladorPartido();
cP.crearPartido(idEquipoLocal, idEquipoVisitante,
fechaPartido,fechaSel,resultado,hora,torParam);

return SUCCESS;
}

Thr method "devolverFecha":
private static PersistenceManager pm =
PMF.get().getPersistenceManager();
//pm is a singleton
public Fecha devolverFecha(Long idFecha, Long torneo) {

Transaction tx = pm.currentTransaction();
try {
tx.begin();
Key k2 = new
KeyFactory.Builder(Torneo.class.getSimpleName(),

torneo).addChild(Fecha.class.getSimpleName(), idFecha)
.getKey();

Fecha f = pm.getObjectById(Fecha.class, k2);

tx.commit();
return f;
} finally {
if (tx.isActive()) {
tx.rollback();
}
//pm.close();
}
}

Regards!
Lisandro

crllvnc

unread,
Jul 24, 2010, 4:43:43 AM7/24/10
to Google App Engine
Solution is simple : you HAVE to persist the object with the SAME pm
instance you used to FETCH the object from the datastore.
I did not read your code, but the error warning tells you that you
probably used 2 different pm (in 2 different methods ?).
Reply all
Reply to author
Forward
0 new messages