I wrote a small test program to demonstrate this problem and the problem persist as expected .
package test;
import protocol.hbm.*;
import server.dao.*;
import org.hibernate.*;
import java.io.*;
/**
* PIForm creation Test
*
*/
public class PIFormCreateTest {
/**
* @param args
*/
public static void main(String[] args)throws Exception{
rawTest();
}
public static void rawTest()throws Exception{
System.out.println("Running Raw Test");
StaffUser stau = new StaffUser("test user name","test description");
Session session = HibernateHelper.getSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
System.out.println("Saving test user");
session.save(stau);
System.out.println("User saved");
tx.commit();
}
catch (Exception e) {
System.out.println("Exception Couldnot save User \nrolling back transaction");
tx.rollback();
System.out.println("Roll back done");
System.out.println("Printing Exception stack trace");
e.printStackTrace();
return;
}
PIForm piform = new PIForm();
piform.getTelephones().add(new Telephone("00993376",Telephone.HOME));
piform.getAddresses().add(new Address("999","South Road","North City","East County","UP7 7DR"));
piform.setEmail("
[email protected]");
piform.setFirstname("Tester");
piform.setLastname("raw Tester");
piform.setForenames("x");
piform.setUser(stau);
piform.setIsmale(true);
try {
tx = session.beginTransaction();
session.save(piform);
tx.commit();
}
catch (Exception e) {
System.out.println("Exception Couldnot save PIForm \nrolling back transaction");
tx.rollback();
System.out.println("Roll back done");
System.out.println("Deleting test user");
session.delete(stau);
System.out.println("Test User deletion done");
System.out.println("Printing Exception stack trace");
e.printStackTrace();
return;
}
pause("Waiting for clean up");
System.out.println("Cleaning up");
tx = session.beginTransaction();
session.delete(piform);
session.delete(stau);
tx.commit();
}
public static void pause(String message)throws Exception{
if(message!=null){
System.out.println(message);
}
System.out.print("Press Enter to Continue...");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
}
}