ciao a tutti!
sto sviluppando un'applicazione web basata su Spring MVC e utilizzando DB4O come database. Il problema è che a volte (ed in maniera apparentemente casuale) quando il framework esegue l'istruzione
Studente studente = (Studente) database.getContainer().ext().getByID(studenteId);
viene fuori un oggetto che ha tutti i campi a null, come testimoniato dalla stampa successiva
System.out.println("**************** " + database.getContainer().ext().getID(studente) + " " + studente.getNome() + " " + studente.getCognome() + " " + studente.getAmico());
Invece, eseguendo questo tipo di query
Studente studente_prototipo = new Studente();
ObjectSet<Studente> studenti = database.getContainer().get( studente_prototipo );
questo problema non si verifica mai.
Ho fatto prove anche con altri tipi di campi (int, double, ecc.) ma sembra che quando l'errore di caricamento si verifica, anche questi ultimi vengano riempiti con il loro valore di default, che è 0.
quale potrebbe essere la causa? forse sto sbagliando modo di fare la query? il problema è stato affrontato e risolto da qualcuno?
public class Studente {
private String nome;
private String cognome;
private Studente amico;
public Studente()
{
}
public Studente(String nome, String cognome)
{
this.nome = nome;
this.cognome = cognome;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public Studente getAmico()
{
return amico;
}
public void setAmico( Studente amico )
{
this.amico = amico;
}
}
public class StudenteController_Dettagli implements Controller
{
private Database database;
public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception
{
int studenteId = Integer.parseInt(arg0.getParameter("id"));
System.out.println(studenteId);
Studente studente = (Studente) database.getContainer().ext().getByID(studenteId);
System.out.println("**************** " + database.getContainer().ext().getID(studente) + " " + studente.getNome() + " " + studente.getCognome());
ModelAndView mav = new ModelAndView("Studente_Dettagli", "studente", studente);
return mav;
}
public Database getDatabase()
{
return database;
}
public void setDatabase( Database database )
{
this.database = database;
}
}