Hello,
I'm new to Hibernate and I want to use it for my new project. I have written some very simple tests with it. I have two problems:
1. I have an entity with an unique constraint (<unique = true>) and when I insert a duplicate record Hibernate raise a JDBCException. How do I make the diference between the UNIQUE CONSTRAINT VIOLATION and other exceptions? My code looks like this:
Code:
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
try
{
session.saveOrUpdate(user);
HibernateUtil.commitTransaction();
}
catch
{
//
}
finally
{
HibernateUtil.closeSession();
}
2. I use DAO for loading/saving objects with hibernate. In every method I have HibernateUtil.getSession(); and HibernateUtil.closeSession(). My problem is when I call a DAO method from another DAO method. In the first method I open the session and the second method closes the session. (because I have HibernateUtil.getSession() and HibernateUtil.closeSession() in every method). The second method is called directly from the user interface, so I can't remove HibernateUtil.getSession() and HibernateUtil.closeSession(). I want the method who opens the session to close the session. Any ideea about how can I make it work?