Thanks Stevko, but I have a problem with the persistence of an
existing object
"Torneo" (with a empty collection of objects "Equipo").
When I add elements to the collection and want to persist,
sometimes persist and sometimes not persist in the
datastore(Restarting the server of the application).
The code involved to add an "Equipo" to "Torneo" (please to see the
comments):
ControladorTorneo cTor = new ControladorTorneo().GetInstance();
torneo = cTor.devolverTorneo(torACargar);
//torACargar is the correct ID and and he returns it correct "torneo"
Equipo equi= new Equipo(nombre,imagen,desc);
cTor.agregarEquipoConTorneo(torneo,equi);
The definition of the class "ControladorTorneo" and methods in
question:
public class ControladorTorneo {
private static ControladorTorneo Instance = null;
public static Torneo miTorneoActual = null;
private final PersistenceManager pm =
PMF.get().getPersistenceManager();
.....
.....
private void CreateInstance() {
if (Instance == null) {
Instance = new ControladorTorneo();
}
}
public Torneo devolverTorneo(Long idTorneo) {
Torneo unTorneo = pm.getObjectById(Torneo.class, idTorneo);
return unTorneo;
}
public void agregarEquipoConTorneo(Torneo unTorneo, Equipo
unEquipo) {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
unTorneo.agregarEquipo(unEquipo);
/*add an "Equipo" to collection "equipos" That has
the class "Torneo"
Debugs adds, but sometimes he does not persist*/
pm.makePersistentAll(unTorneo);
tx.commit();
System.out.println("persistioTorneoConEquipo");
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
}
The class "Equipo":
@PersistenceCapable(identityType =
IdentityType.APPLICATION,detachable="true")
public class Equipo implements Serializable {
....
.....
public Equipo(String nombre, String imagen, String desc) {
//super();
this.nombre = nombre;
this.imagen = imagen;
this.desc = desc;
}
Something to modify in these methods?
Regards and thanks!
On Jan 3, 2:34 pm, "A. Stevko" <[email protected]> wrote:
> Yes it is detachable.
> So you need to detach & re-attach the object using the code samples
> inhttp://www.jpox.org/docs/1_2/jdo/attach_detach.html
>
>
>
>
>
> On Mon, Jan 3, 2011 at 5:44 AM, lisandrodc <[email protected]> wrote:
> > Hi Stevko! The class "Torneo", it's definite:
>
> > @PersistenceCapable(identityType=IdentityType.APPLICATION,detachable="true"
> > )
> > public class Torneo implements Serializable {
> > /*
> > * @author Lisandro della Croce
> > */
> > �...@primarykey
> > �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>
> > private Key id;
> > �...@persistent
> > private String nombre;
> > ......
> > �...@persistent(defaultFetchGroup = "true")
> > private List<Equipo> equiposTorneo;
>
> > Is correct?
>
> > Regards
>
> > On Jan 3, 9:06 am, "A. Stevko" <[email protected]> wrote:
> > > I think the inconsistent saving that you are experiencing has to do with
> > how
> > > the parent object, Torneo, is being accessed.
> > > You are passing an database object reference into a transaction.
> > > Is that object "detachable" ?
>
> > > If not, then you should be retrieving it and updating it within the same
> > > transaction.
> > > See Updating an Object inhttp://
> > code.google.com/appengine/docs/java/datastore/creatinggettinga...
>
> > > If so, then you should re-attach it prior to updating it.
> >http://www.jpox.org/docs/1_2/jdo/attach_detach.html
>
> > > Hope this helps.
> > > --Andy
>
> > > On Mon, Jan 3, 2011 at 3:47 AM, lisandrodc <[email protected]> wrote:
> > > > Hi! I have a problem with the persistence of an existing object
> > > > "Torneo" (with a empty collection of objects "Equipo").
> > > > When I add elements to the collection and want to persist,
> > > > sometimes persist and sometimes not persist in the
> > > > datastore(Restarting the server of the application). The code of
> > > > example:
> > > > public void agregarEquipoConTorneo(Torneo unTorneo, Equipo unEquipo)
> > > > {
> > > > /*add Equipo with a existing "Torneo" in the
> > > > datastore, the "unTorneo"(param) class obtain with:
> > > > Torneo b =
> > > > pm.getObjectById(model.Torneo.class, idTorneo);*/
> > > > Transaction tx = pm.currentTransaction();
> > > > try {
> > > > tx.begin();
> > > > unTorneo.agregarEquipo(unEquipo);
> > > > //add unEquipo to collection "equipos"
> > > > pm.makePersistentAll(unTorneo);
> > > > tx.commit();
> > > > System.out.println("persistioTorneoConEquipo");
> > > > } finally {
> > > > pm.close();
> > > > if (tx.isActive()) {
> > > > tx.rollback();
> > > > }
> > > > }
> > > > Does it design someone of what this one happening?
> > > > Thanks!
> > > > Regards
> > > > Lisandro
>
> > > > --
> > > > 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]<google-appengine-java%2B
> > > > [email protected]><google-appengine-java%2B
> > [email protected]>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/google-appengine-java?hl=en.
>
> > > --
> > > -- A. Stevko
> > > ===========
> > > "If everything seems under control, you're just not going fast enough."
> > M.
> > > Andretti
>
> > --
> > 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]<google-appengine-java%2B
> > [email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-appengine-java?hl=en.
>
> --
> -- A. Stevko
> ===========
> "If everything seems under control, you're just not going fast enough." M.
> Andretti
--
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.