use of javax.persistence.EntityManagerFactory in project OpenAttestation by OpenAttestation.
the class PersistenceManager method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent sce) {
for (String factoryName : factories.keySet()) {
EntityManagerFactory factory = factories.get(factoryName);
if (factory != null && factory.isOpen()) {
log.info("PersistenceManager closing factory {} in contextDestroyed", factoryName);
factory.close();
}
factories.remove(factoryName);
}
}
use of javax.persistence.EntityManagerFactory in project OpenMEAP by OpenMEAP.
the class ModelTestUtils method resetTestDb.
public static void resetTestDb() {
if (persistenceBeans != null) {
EntityManagerFactory emf = getEntityManagerFactory();
emf.close();
persistenceBeans.close();
}
persistenceBeans = null;
File testDbFile = new File(OPENMEAP_TEST_DB);
if (testDbFile.exists() && !testDbFile.delete()) {
throw new RuntimeException("Could not delete " + OPENMEAP_TEST_DB);
}
}
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 spring-framework by spring-projects.
the class JpaTransactionManager method createEntityManagerForTransaction.
/**
* Create a JPA EntityManager to be used for a transaction.
* <p>The default implementation checks whether the EntityManagerFactory
* is a Spring proxy and unwraps it first.
* @see javax.persistence.EntityManagerFactory#createEntityManager()
* @see EntityManagerFactoryInfo#getNativeEntityManagerFactory()
*/
protected EntityManager createEntityManagerForTransaction() {
EntityManagerFactory emf = getEntityManagerFactory();
if (emf instanceof EntityManagerFactoryInfo) {
emf = ((EntityManagerFactoryInfo) emf).getNativeEntityManagerFactory();
}
Map<String, Object> properties = getJpaPropertyMap();
return (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager());
}
use of javax.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class EntityManagerFactoryAccessor method createEntityManager.
/**
* Obtain a new EntityManager from this accessor's EntityManagerFactory.
* <p>Can be overridden in subclasses to create specific EntityManager variants.
* @return a new EntityManager
* @throws IllegalStateException if this accessor is not configured with an EntityManagerFactory
* @see javax.persistence.EntityManagerFactory#createEntityManager()
* @see javax.persistence.EntityManagerFactory#createEntityManager(java.util.Map)
*/
protected EntityManager createEntityManager() throws IllegalStateException {
EntityManagerFactory emf = getEntityManagerFactory();
Assert.state(emf != null, "No EntityManagerFactory specified");
Map<String, Object> properties = getJpaPropertyMap();
return (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager());
}
Aggregations