Hi! I have a problem for persist a relation one to many.
The problem is that when update the object "Torneo" with a new
"Equipo", at get for
the method Torneo b = pm.getObjectById(Torneo.class, idTorneo); the
b.getEquiposTorneo that is a collection is null.On having added a
"Equipo" to "Torneo", stored the objects "Equipo " in the database,
but everything returns to the reuperarlo except the collections.
The Code:
The "Torneo" class:
public class Torneo implements Serializable{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String nombre;
@Persistent
private String imagen;
@Persistent
private Date fechaInicio;
@Persistent
private Date fechaFin;
@Persistent
private List<Fecha> fechasTorneo;
@Persistent
private List<Usuario> usuarios;
@Persistent
private List<Equipo> equiposTorneo;
// with(getter and setter)
.....
The Equipo class:
public class Equipo implements Serializable{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
@Persistent
private String nombre;
@Persistent
private String imagen;
@Persistent
private String desc;
@Persistent
private Torneo torneo;
....
.....
}
Add an "Equipo" class to a "Torneo" class:
public void crearTorneo(String nombre, Date fechaInicio, Date
fechaFin,
String imagen) {
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Torneo torneo = new Torneo(nombre, imagen, fechaInicio,
fechaFin);
System.out.println("nombre " + nombre);
pm.makePersistent(torneo);
// Here I see for the point that the collection
is empty not void (because the set in the constructor)
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
}
}
public Torneo devolverTorneo(Long idTorneo) {
Torneo b = pm.getObjectById(Torneo.class, idTorneo);
return b;
//The method return the object for update
}
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.