Generated sql:
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into PERSON (name, address, id) values (?, ?, ?)
Everything seems to be working - no errors at all. But my class is not being
saved to the database! I get the session, do the save, the flush etc - but
no action in the database itself.
Should I not be seeing the actual SQL and not the ? ? ? business? My class
is folowing all the right rules (private members, no arg constructor etc
CODE:
Person person1 = new Person();
person1.setName("Basil Fawlty");
person1.setAddress("Fawlty Towers, UK");
try {
Session session = HibernateUtil.currentSession();
session.save(person1);
session.flush();
HibernateUtil.closeSession();
} catch (Exception ex) {
System.out.println("Problem with servlet code: " + ex.getMessage());
}
help appreciated.
Mark Scott - 23 Dec 2004 11:35 GMT
[...]
> Person person1 = new Person();
> person1.setName("Basil Fawlty");
[quoted text clipped - 9 lines]
> System.out.println("Problem with servlet code: " + ex.getMessage());
> }
Do the work in a Transaction. Look at the code idiom in the javadoc for
Session (or look at the example in the Hibernate doc, just under the
definition of HibernateUtil (assuming it's that implementation you're
using)).
HTH.

Signature
Mark Scott
mark@codebrewer.com
GPG Key ID: 0x2CCE1173 - signed/encrypted mail preferred