Keep in mind that I took lot of effort in arranging the code within the [c o d e] tags Make it as a practice to use available tools v.z. code tags while presenting your problem.
Within you try-catch block, you are catching only HibernateException and ignoring every other exception.
Check to see if this code is also not working.
Code:
public class Insert {
public static void main(String[] args)
{
BasicConfigurator.configure();
Logger logger = Logger.getLogger(Insert.class);
Session session = null;
Transaction tx = null;
SessionFactory sessionFactory = null;
try
{
// have you specified hibernate_cfg.xml file
// to use this option below
// Configuration configuration = new Configuration();
// configuration.configure();
// if you havent specified any mapping file or class
// you could add programmatically as follows
Configuration configuration = new Configuration();
configuration.addClass( Employee.class ); // assuming Employee.hbm.xml is available
configuration.addClass( Department.class ); //// assuming Department.hbm.xml is available
sessionFactory = configuration.buildSessionFactory();
session = sessionFactory.openSession();
String query = "from Employee e, Department d where e.DEPTID=d.DEPTID ";
Query qry = session.createQuery(query);
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println(" INFORMATION ");
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
Iterator i = qry.iterate();
Object []pair=(Object[])i.next();
Employee e=(Employee) pair[0];
Department d=(Department)pair[1];
e.show();
d.show();
}
//catch (HibernateException e)
catch( Exception e )
{
throw e;
}
finally
{
if (session != null)
{
try
{
session.close();
}
catch (HibernateException ignore)
{// ignore
}
}
if (sessionFactory != null)
{
try
{
sessionFactory.close();
}
catch (HibernateException e)
{// ignore
}
}
}
}
}