Search in sources :

Example 71 with EntityManagerFactory

use of javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.

the class DdlInWildFlyUsingBmtAndEmfTest method testCreateThenDrop.

@Test
public void testCreateThenDrop() throws Exception {
    URL persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource(PERSISTENCE_XML_RESOURCE_NAME);
    if (persistenceXmlUrl == null) {
        persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource('/' + PERSISTENCE_XML_RESOURCE_NAME);
    }
    assertNotNull(persistenceXmlUrl);
    ParsedPersistenceXmlDescriptor persistenceUnit = PersistenceXmlParser.locateIndividualPersistenceUnit(persistenceXmlUrl);
    // creating the EMF causes SchemaCreator to be run...
    EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, Collections.emptyMap()).build();
    // closing the EMF causes the delayed SchemaDropper to be run...
    // wrap in a transaction just to see if we can get this to fail in the way the WF report says;
    // in my experience however this succeeds with or without the transaction
    final TransactionManager tm = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(JtaPlatform.class).retrieveTransactionManager();
    tm.begin();
    Transaction txn = tm.getTransaction();
    emf.close();
    txn.commit();
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) JBossAppServerJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform) JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) Transaction(javax.transaction.Transaction) UserTransaction(javax.transaction.UserTransaction) TransactionManager(javax.transaction.TransactionManager) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) EntityManagerFactory(javax.persistence.EntityManagerFactory) URL(java.net.URL) Test(org.junit.Test)

Example 72 with EntityManagerFactory

use of javax.persistence.EntityManagerFactory in project minijax by minijax.

the class LiquibaseHelperTest method testCloseEntityManagerFactoryException.

@Test
public void testCloseEntityManagerFactoryException() throws Exception {
    final EntityManagerFactory emf = mock(EntityManagerFactory.class);
    doThrow(new RuntimeException("Boom")).when(emf).close();
    LiquibaseHelper.closeQuietly(emf);
    verify(emf).close();
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) Test(org.junit.Test)

Example 73 with EntityManagerFactory

use of javax.persistence.EntityManagerFactory in project minijax by minijax.

the class CloseUtilsTest method testEntityManager.

@Test
public void testEntityManager() {
    final EntityManagerFactory emf = Persistence.createEntityManagerFactory("testdb");
    assertNotNull(emf);
    assertTrue(emf.isOpen());
    final EntityManager em = emf.createEntityManager();
    assertNotNull(em);
    assertTrue(em.isOpen());
    CloseUtils.closeQuietly(em);
    assertFalse(em.isOpen());
    CloseUtils.closeQuietly(emf);
    assertFalse(emf.isOpen());
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) Test(org.junit.Test)

Example 74 with EntityManagerFactory

use of javax.persistence.EntityManagerFactory in project tesb-rt-se by Talend.

the class PersonApplication method getSingletons.

@Override
public Set<Object> getSingletons() {
    Set<Object> classes = new HashSet<Object>();
    PersonInfoStorage storage = new PersonInfoStorage();
    try {
        Class.forName("org.hsqldb.jdbcDriver");
        EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("persistenceUnitOpenJPA");
        storage.setEntityManager(emFactory.createEntityManager());
        Map<String, String> beanPropertiesMap = new HashMap<String, String>();
        beanPropertiesMap.put("fatherName", "father.name");
        beanPropertiesMap.put("father", "father.name");
        beanPropertiesMap.put("childName", "children.name");
        storage.setBeanProperties(beanPropertiesMap);
        storage.init();
    } catch (Throwable ex) {
        throw new RuntimeException(ex);
    }
    PersonServiceImpl personService = new PersonServiceImpl();
    personService.setStorage(storage);
    classes.add(personService);
    SearchService searchService = new SearchService();
    searchService.setStorage(storage);
    classes.add(searchService);
    // custom providers
    classes.add(new PersonExceptionMapper());
    JSONProvider<?> provider = new JSONProvider<Object>();
    provider.setIgnoreNamespaces(true);
    classes.add(provider);
    classes.add(new SearchContextProvider());
    return classes;
}
Also used : HashMap(java.util.HashMap) PersonInfoStorage(service.advanced.PersonInfoStorage) SearchContextProvider(org.apache.cxf.jaxrs.ext.search.SearchContextProvider) PersonServiceImpl(service.advanced.PersonServiceImpl) EntityManagerFactory(javax.persistence.EntityManagerFactory) SearchService(service.advanced.SearchService) JSONProvider(org.apache.cxf.jaxrs.provider.json.JSONProvider) PersonExceptionMapper(service.advanced.PersonExceptionMapper) HashSet(java.util.HashSet)

Example 75 with EntityManagerFactory

use of javax.persistence.EntityManagerFactory in project mapping-benchmark by arnaudroger.

the class BatooBenchmark method main.

public static void main(String[] args) throws Exception {
    ConnectionParam connParam = new ConnectionParam();
    connParam.db = DbTarget.HSQLDB;
    connParam.init();
    EntityManagerFactory sf = Persistence.createEntityManagerFactory("jpa");
    EntityManager session = sf.createEntityManager();
    try {
        Query query = session.createQuery("select s from MappedObject16 s");
        query.setMaxResults(2);
        List<MappedObject16> sr = query.getResultList();
        for (MappedObject16 o : sr) {
            System.out.println("o. = " + o.getEmail());
            System.out.println("o. = " + o.getField12());
        }
    } finally {
        session.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) MappedObject16(org.simpleflatmapper.jpa.beans.MappedObject16) Query(javax.persistence.Query) EntityManagerFactory(javax.persistence.EntityManagerFactory) ConnectionParam(org.simpleflatmapper.db.ConnectionParam)

Aggregations

EntityManagerFactory (javax.persistence.EntityManagerFactory)302 EntityManager (javax.persistence.EntityManager)103 Test (org.junit.Test)90 HashMap (java.util.HashMap)48 EntityTransaction (javax.persistence.EntityTransaction)30 EJBException (javax.ejb.EJBException)22 Map (java.util.Map)17 AssertionFailedError (junit.framework.AssertionFailedError)17 TestFailureException (org.apache.openejb.test.TestFailureException)17 ArrayList (java.util.ArrayList)15 JMSException (javax.jms.JMSException)15 KieSession (org.kie.api.runtime.KieSession)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)14 Properties (java.util.Properties)13 InitialContext (javax.naming.InitialContext)13 List (java.util.List)12 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 RemoteException (java.rmi.RemoteException)11 Query (javax.persistence.Query)11 PrintWriter (java.io.PrintWriter)10