Hi!Marcus, now I use your pattern for transactions:
The code of the method:
public void crearPartido(Long idEqLocal, Long idEqVisitante, Date
fecha,
Fecha fechaAgreg, String resultado, String hora,Long
idTorneo){
PersistenceManager pm =
JDOHelper.getPersistenceManager(fechaAgreg);
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();
}
}
But now, the error is:
"Object with id "com.google.appengine.api.datastore.Key:Torneo(1)/
Equipo(3)" is managed by a different Object Manager".
I try also changed in the code:
"PersistenceManager pm = getPersistenceManager();
For:
"PersistenceManager pm =
JDOHelper.getPersistenceManager(fechaAgreg);"(But mistake is the one
that already I enunciated).
The link:
http://stackoverflow.com/questions/1403515/appengine-datastore-object-with-id-is-managed-by-a-different-object-manager
Regards
Lisandro
On 19 jul, 05:15, Marcus Brody <[email protected]> wrote:
> try follow this pattern for transactions
>
> public void doSomthingWithEntity(T entity) {
>
> PersistenceManager pm = getPersistenceManager();
> Transaction transaction = pm.currentTransaction();
>
> try {
> transaction.begin();
> // do something with entity, get, persist, delete
> // pm.makePersistent(entity);
>
> transaction.commit();
> }
> finally {
> if (transaction != null && transaction.isActive())
> transaction.rollback();
> pm.close();
> }
> }
>
> On Jul 18, 11:01 pm, lisandrodc <[email protected]> wrote:
>
> > Hi! I have a problem with active transaction.When I try to guard in
> > the datastore, says:
>
> > "La transaccion esta activo todavia. Debe cerrar las transacciones
> > usando los metodos commit() o rollback()."
>
> > As closure all the transactions?
> > The method is:
>
> > PersistenceManager pm2 = JDOHelper.getPersistenceManager(fechaAgreg);
>
> > Transaction tx = pm2.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);
>
> > fechaAgreg.agregarPartido(par1);
> > pm2.makePersistent(fechaAgreg);
> > tx.commit();
>
> > } finally {
> > pm2.close();
>
> > if (tx.isActive()) {
> > tx.rollback();
> > }
> > }
>
> > }
>
> > Regards
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.