// Path: datastore/sql/JPA/src/main/java/com/jpa/dao/HumanDAO.java
// public class HumanDAO extends GenericHibernateDAO<Human, Serializable> {
// 
//     //private Criteria criteria = HibernateUtil.getSession().createCriteria(Human.class); 
// 
//     public Human getAUserByID(long userID) {
//         List<Human> resultList = findByCriteria(Restrictions.eq("id", userID));
//         if (!resultList.isEmpty()) {
//             return findByCriteria(Restrictions.eq("id", userID)).get(0);
//         }
//         return null;
//     }
// 
//     public List<Human> getAllusers() {
//         return findAll();
//     }
// 
//     public List<Human> findByExample(Human exampleInstance) {
//         return null;
//     }
// 
// }
// 
// Path: datastore/sql/JPA/src/main/java/com/jpa/model/Human.java
// @Entity(name = "human")
// public class Human {
// 
//     private long userID;
//     private String firstName;
//     private String lastName;
//     private String gender;
//     private int age;
// 
//     @Id
//     @Column(name = "id")
//     public long getUserID() {
//         return userID;
//     }
// 
//     public void setUserID(long userID) {
//         this.userID = userID;
//     }
// 
//     @Column(name = "first_name")
//     public String getFirstName() {
//         return firstName;
//     }
// 
//     public void setFirstName(String firstName) {
//         this.firstName = firstName;
//     }
// 
//     @Column(name = "last_name")
//     public String getLastName() {
//         return lastName;
//     }
// 
//     public void setLastName(String lastName) {
//         this.lastName = lastName;
//     }
// 
//     @Column(name = "gender")
//     public String getGender() {
//         return gender;
//     }
// 
//     public void setGender(String gender) {
//         this.gender = gender;
//     }
// 
//     @Column(name = "age")
//     public int getAge() {
//         return age;
//     }
// 
//     public void setAge(int age) {
//         this.age = age;
//     }
// 
// }
// 
// Path: datastore/sql/JPA/src/main/java/com/jpa/util/HibernateUtil.java
// @SuppressWarnings({"unchecked", "rawtypes", "unused"})
// public class HibernateUtil {
// 
//     private static final Logger log = Logger.getLogger(HibernateUtil.class);
// 
//     /*
//      * Since we will be using annotated classes, it is best to maintain a list
//      * of such classes so we add them up easily
//      */
//     private static final List<Class<?>> classList = new ArrayList() {{
//         add(com.jpa.model.Human.class);
//     }};
//     private static final SessionFactory sessionFactory = buildSessionFactory();
// 
//     private static SessionFactory buildSessionFactory() {
//         /*
//          * Load up the configuration using the hibernate.cfg.xml
//          */
//         Configuration configuration = new Configuration();
//         configuration.configure("hibernate.cfg.xml");
// 
//         /*
//          * Build the registry using the properties in the configuration
//          */
//         ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
//                 configuration.getProperties()).build();
// 
//         /*
//          * Now load the classes
//          */
//         for (Class<?> pojoClass : classList) {
//             log.info("Adding annotated class : " + pojoClass.getCanonicalName());
//             configuration.addAnnotatedClass(pojoClass);
//         }
// 
//         /*
//          * and finally buils the session factory
//          */
//         return configuration.buildSessionFactory(serviceRegistry);
//     }
// 
//     public static SessionFactory getSessionFactory() {
//         return sessionFactory;
//     }
// 
//     public static void shutdown() {
//         getSessionFactory().close();
//     }
// 
//     /**
//      * The main utility method to be used to retreive the transaction.
//      *
//      * @return {@link Transaction} The transaction of the current session
//      */
//     public static Transaction getTransaction() {
//         Session s = getSessionFactory().getCurrentSession();
//         Transaction tx = s.beginTransaction();
//         tx.setTimeout(10);
//         return tx;
//         //return getSessionFactory().getCurrentSession().beginTransaction();;
//     }
// 
// }


import com.jpa.dao.HumanDAO;
import com.jpa.model.Human;
import com.jpa.util.HibernateUtil;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.fail;

            for (int i = 0; i < 15; i++) {
                humanDAO.setSession(session);
                Human aPerson = new Human();
                aPerson.setUserID(i);
                aPerson.setFirstName("Frank" + i);
                aPerson.setLastName("Bob" + i);
                aPerson.setAge(42);
                aPerson.setGender("Male");
                humanDAO.makePersistent(aPerson);
                log.info("Inserted human into table ..... ");
            }

            // Now attempt to fetch this record with ID
            log.info("Fetching inserted user record from DB ...... ");
            Human human2 = humanDAO.getAUserByID(0);
            log.info("Got user with name " + human2.getFirstName());

            tx.rollback();
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    @Test
    public void testMultiInsertFetchUniqueTransaction() {
        for (int i = 0; i < 15; i++) {
            try {
                final Session session = HibernateUtil.getSessionFactory().openSession();
                Transaction tx = session.beginTransaction();
// Path: datastore/sql/JPA/src/main/java/com/jpa/dao/HumanDAO.java
// public class HumanDAO extends GenericHibernateDAO<Human, Serializable> {
// 
//     //private Criteria criteria = HibernateUtil.getSession().createCriteria(Human.class); 
// 
//     public Human getAUserByID(long userID) {
//         List<Human> resultList = findByCriteria(Restrictions.eq("id", userID));
//         if (!resultList.isEmpty()) {
//             return findByCriteria(Restrictions.eq("id", userID)).get(0);
//         }
//         return null;
//     }
// 
//     public List<Human> getAllusers() {
//         return findAll();
//     }
// 
//     public List<Human> findByExample(Human exampleInstance) {
//         return null;
//     }
// 
// }
// 
// Path: datastore/sql/JPA/src/main/java/com/jpa/model/Human.java
// @Entity(name = "human")
// public class Human {
// 
//     private long userID;
//     private String firstName;
//     private String lastName;
//     private String gender;
//     private int age;
// 
//     @Id
//     @Column(name = "id")
//     public long getUserID() {
//         return userID;
//     }
// 
//     public void setUserID(long userID) {
//         this.userID = userID;
//     }
// 
//     @Column(name = "first_name")
//     public String getFirstName() {
//         return firstName;
//     }
// 
//     public void setFirstName(String firstName) {
//         this.firstName = firstName;
//     }
// 
//     @Column(name = "last_name")
//     public String getLastName() {
//         return lastName;
//     }
// 
//     public void setLastName(String lastName) {
//         this.lastName = lastName;
//     }
// 
//     @Column(name = "gender")
//     public String getGender() {
//         return gender;
//     }
// 
//     public void setGender(String gender) {
//         this.gender = gender;
//     }
// 
//     @Column(name = "age")
//     public int getAge() {
//         return age;
//     }
// 
//     public void setAge(int age) {
//         this.age = age;
//     }
// 
// }
// 
// Path: datastore/sql/JPA/src/main/java/com/jpa/util/HibernateUtil.java
// @SuppressWarnings({"unchecked", "rawtypes", "unused"})
// public class HibernateUtil {
// 
//     private static final Logger log = Logger.getLogger(HibernateUtil.class);
// 
//     /*
//      * Since we will be using annotated classes, it is best to maintain a list
//      * of such classes so we add them up easily
//      */
//     private static final List<Class<?>> classList = new ArrayList() {{
//         add(com.jpa.model.Human.class);
//     }};
//     private static final SessionFactory sessionFactory = buildSessionFactory();
// 
//     private static SessionFactory buildSessionFactory() {
//         /*
//          * Load up the configuration using the hibernate.cfg.xml
//          */
//         Configuration configuration = new Configuration();
//         configuration.configure("hibernate.cfg.xml");
// 
//         /*
//          * Build the registry using the properties in the configuration
//          */
//         ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
//                 configuration.getProperties()).build();
// 
//         /*
//          * Now load the classes
//          */
//         for (Class<?> pojoClass : classList) {
//             log.info("Adding annotated class : " + pojoClass.getCanonicalName());
//             configuration.addAnnotatedClass(pojoClass);
//         }
// 
//         /*
//          * and finally buils the session factory
//          */
//         return configuration.buildSessionFactory(serviceRegistry);
//     }
// 
//     public static SessionFactory getSessionFactory() {
//         return sessionFactory;
//     }
// 
//     public static void shutdown() {
//         getSessionFactory().close();
//     }
// 
//     /**
//      * The main utility method to be used to retreive the transaction.
//      *
//      * @return {@link Transaction} The transaction of the current session
//      */
//     public static Transaction getTransaction() {
//         Session s = getSessionFactory().getCurrentSession();
//         Transaction tx = s.beginTransaction();
//         tx.setTimeout(10);
//         return tx;
//         //return getSessionFactory().getCurrentSession().beginTransaction();;
//     }
// 
// }


// Path: datastore/sql/JPA/src/test/java/com/test/insertion/InsertionTest.java
import com.jpa.dao.HumanDAO;
import com.jpa.model.Human;
import com.jpa.util.HibernateUtil;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.fail;


            for (int i = 0; i < 15; i++) {
                humanDAO.setSession(session);
                Human aPerson = new Human();
                aPerson.setUserID(i);
                aPerson.setFirstName("Frank" + i);
                aPerson.setLastName("Bob" + i);
                aPerson.setAge(42);
                aPerson.setGender("Male");
                humanDAO.makePersistent(aPerson);
                log.info("Inserted human into table ..... ");
            }

            // Now attempt to fetch this record with ID
            log.info("Fetching inserted user record from DB ...... ");
            Human human2 = humanDAO.getAUserByID(0);
            log.info("Got user with name " + human2.getFirstName());

            tx.rollback();
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    @Test
    public void testMultiInsertFetchUniqueTransaction() {
        for (int i = 0; i < 15; i++) {
            try {
                final Session session = HibernateUtil.getSessionFactory().openSession();
                Transaction tx = session.beginTransaction();
                HumanDAO humanDAO = new HumanDAO();