When I commit the transaction, I get the error below:
Code:
Exception in thread "main" org.hibernate.SessionException: Session was already closed
at org.hibernate.impl.SessionImpl.close(SessionImpl.java:270)
at business.commands.LockParagraph.ejecutar(LockParagraph.java:88)
at business.commands.Invoker.ejecutar(Invoker.java:21)
at business.Services.lockParagraph(Services.java:403)
at business.TranformerInputOutput.lockParagraph(TranformerInputOutput.java:298)
at business.TranformerInputOutput.main(TranformerInputOutput.java:45)
The code is the next, I must be forgotting something:
Code:
ParagraphDAO paragraphDAO=(ParagraphDAO)new ParagraphDAO().getInstance();
try
{
session=paragraphDAO.getSession();
//s.flush();
tx=session.beginTransaction();
Paragraph para=paragraphDAO.get(id);
if(para.isLock())
{
throw (new ViolationLockingParagraph());
}
else
{
para.setLock(true);
}
paragraphDAO.saveOrUpdate(para);
//tx.commit();
parameterList.put("LOCKPARAGRAPH_RESUL",para);
}
catch(Exception excep)
{
if(tx!=null)
{
try
{
tx.rollback();
}
catch(HibernateException hibernateExcep)
{
System.out.println("EXCEPCTION, in LockParagraph class, closing transaction: "+hibernateExcep.getMessage());
hibernateExcep.printStackTrace();
throw hibernateExcep;
}
}
System.out.println("Exception in class LockParagraph: "+excep.getMessage());
excep.printStackTrace();
}
finally
{
try
{
session.close();
}
catch(HibernateException hibernateException)
{
throw hibernateException;
}
}
Many thanks.
Regards