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();
}
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();
}
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());
}
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;
}
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();
}
}
Aggregations