Cecile,
your mapping looks fine - I tried it out using hsql (not Oracle, so so my id generator differs from your mappings) and it worked as it should. The problem appears to be that you are not commiting the transaction. You need to surround your unit of work by a transaction:
Code:
public void runTest(SessionFactory sf)throws Exception {
long caseId = 999;
Session session = sf.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction(); //NB begin the unit of work
Report report=new Report();
ReportedPatient reportedPatient=new ReportedPatient();
report.setReportedPatient(reportedPatient);
reportedPatient.setReport(report);
report.setCaseId(Long.toString(caseId));
report.setEmployeeId(1);
report.setInternalCaseId("2");
report.setOriginCode("SPON");//SPON or STUD
report.setReportType("AE");
report.setSequenceNumber(1);
reportedPatient.setGenderCode("M");
session.save(report);
tx.commit(); //NB commit the unit of work
} catch (Exception e){
if (tx != null) {
try {
tx.rollback();
} catch (Exception e2){
System.out.println("runTest rollback failed" + e2);
throw e2;
}
}
System.out.println("runTest failed: " + e);
throw e;
} finally {
try {
if (session.isOpen()) {
session.close();
}
}catch (Exception e3){
throw e3;
}
}
System.out.println("At end of runTest");
}
The Hibernate Session disables auto commit on the connection so you need to commit the transaction yourself.
I hope that this solves your problem. Good luck!
Grainne.