From my junit test I’m calling a simple method to clear my table:
@AfterClass
public static void runAfterClass() {
//Clear db contents after tests
// NOTE this clears ALL data from the table
try {
System.out.println("deleting db contents");
HibFunction.clearTable();
} catch (Exception e) {
System.out.println("Couldnt delete db contents");
e.printStackTrace();
}
The clearTable looks like:
public static void clearTable()
{
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try{
transaction = session.beginTransaction();
session.createQuery("delete from metadataPoC.hib.TestHib").executeUpdate();
transaction.commit();
}catch (HibernateException e) {
transaction.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
All fairly simple stuff however my console output goes no further than:
deleting db contents
I am unsure why exactly a simple delete from classname
can cause such issues. The programme has just been hanging for 10mins with no failure or result from the junit test.
Edit
However I’ve isolated the problem to the clearTable() method moved it around in the code and as soon as it entered, hangs!
I’m not exactly sure why exactly, from the info I’ve found online my method seems correct from what I can see. But it has to be this method. I placed it in my @BeforeClass and the test just frozen when it got to it.
Bottom line there is a problem with the clearTable() method. Thou I’ve no idea what 🙁
EDIT 2
tracked down the problem to the executeupdate portion of the command for whatever reason it just stalls once it gets to the:
ParseUtil.encodePath(String, boolean) line: 100
It’s probably a deadlock between transaction of
clearTable()method and transaction of the test method.Make sure that you complete (commit or rollback) all transactions when leaving the test method.