in p 33 and p 35 code starts with Session s = getSessionFactory().openSession();
further on i read about creating SessionFactory and later (p129)
i read Session s = sessions.openSession();
i also read (cant remember where) creating a session is inexpensive.
This said, i've a method that starts with:
Code:
public void guardaConvencao() throws HibernateException, ParseException {
sessao = Sessao.currentSession();
Transaction t = sessao.beginTransaction();
String nomeConvencao = rg.jTextFieldCv.getText();
//...
Convencao cv = new Convencao();
cv.setNomeConvencao(nomeConvencao);
//...
sessao.save(cv);
t.commit();
/**
* se fecho a sessão, quando clico em inserir novamente dá erro ao dizer
* q a sessão está fechada
*
* resolução: na classe sessão fiz:
* if (s == null || !s.isOpen()) {
*/
sessao.close();
}
this method is called when one clicks submit in a gui button.
So far so good, but if user submits again, i get an error stating session is closed!
In order to turn this around i changed HibernateUtil method like this:
Code:
if (s == null || !s.isOpen()) {
and now works fine
i've the sensation this isnt abslolutely correct, but i wonder where in book i can solve this in another way
thanks in advance