Search in sources :

Example 6 with Dog

use of org.eclipse.persistence.jpa.test.basic.model.Dog in project eclipselink by eclipse-ee4j.

the class TestDB2Platform method createDogs.

private List<Dog> createDogs(EntityManagerFactory emf) throws Exception {
    EntityManager em = emf.createEntityManager();
    try {
        ArrayList<Dog> dogList = new ArrayList<Dog>();
        em.getTransaction().begin();
        for (int i = 10; i > 0; i--) {
            Dog aDog = new Dog();
            aDog.setName("Dog " + i);
            em.persist(aDog);
            dogList.add(aDog);
        }
        em.getTransaction().commit();
        return dogList;
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) ArrayList(java.util.ArrayList) Dog(org.eclipse.persistence.jpa.test.basic.model.Dog)

Aggregations

EntityManager (jakarta.persistence.EntityManager)6 Dog (org.eclipse.persistence.jpa.test.basic.model.Dog)6 Test (org.junit.Test)5 Person (org.eclipse.persistence.jpa.test.basic.model.Person)4 XmlFish (org.eclipse.persistence.jpa.test.basic.model.XmlFish)4 EntityTransaction (jakarta.persistence.EntityTransaction)3 HashMap (java.util.HashMap)3 EntityManagerFactoryImpl (org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl)3 ConnectionPolicy (org.eclipse.persistence.sessions.server.ConnectionPolicy)3 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)3 PersistenceException (jakarta.persistence.PersistenceException)1 RollbackException (jakarta.persistence.RollbackException)1 StoredProcedureQuery (jakarta.persistence.StoredProcedureQuery)1 ArrayList (java.util.ArrayList)1 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)1 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)1