Hi all, this is my first post on this forums. I'm trying to persist a simple entity. Look at the following code:
Code:
Configuration config = new Configuration();
config.configure();
SessionFactory factory = config.buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
Date birthDate = new GregorianCalendar(1979, 8, 20).getTime();
Date entranceDate = new GregorianCalendar().getTime();
Student student = new Student("David", "Marco",
"300001", birthDate, "001", entranceDate);
session.save(student);
tx.commit();
student.setSsn("SSN300001");
session.flush();
session.close();
As you'll see, the managed 'student' object is modified through a set method after the transaction is commited, but out of the the scope of any transaction. Thereafter, the code makes an explicit call to Session.flush(). Hibernate produces the following output:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select max(id) from STUDENT
Hibernate: insert into STUDENT (FIRST_NAME, LAST_NAME, SSN, BIRTHDATE, STD_NO, ENTRANCE_DATE, id) values (?, ?, ?, ?, ?, ?, ?)
Hibernate: update STUDENT set FIRST_NAME=?, LAST_NAME=?, SSN=?, BIRTHDATE=?, STD_NO=?, ENTRANCE_DATE=? where id=?But the database is never updated!! It remains with the values supplied to the entity when the transaction was commited. Why?? Isn't the session object synchonized with the database and therefore their managed entities as well?
Thanks in advance.