Consider the hierarchy :
And the following classes and xml :
public static void main(String[] args) {
try{
// factory = new Configuration().configure().buildSessionFactory();
factory = new AnnotationConfiguration().
configure().
//addPackage("com.xyz") //add package if used.
addAnnotatedClass(Employee.class).
buildSessionFactory();
}catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}//you can write like this in your test class inside main method.this way you will be able to do the things using annotaions only