Search in sources :

Example 1 with HibernateEntityManagerFactory

use of org.hibernate.jpa.HibernateEntityManagerFactory in project hibernate-orm by hibernate.

the class EntityManagerFactoryUnwrapTest method testEntityManagerCanBeUnwrappedToHibernateEntityManagerFactory.

@Test
public void testEntityManagerCanBeUnwrappedToHibernateEntityManagerFactory() {
    org.hibernate.jpa.HibernateEntityManagerFactory hibernateEntityManagerFactory = entityManagerFactory.unwrap(org.hibernate.jpa.HibernateEntityManagerFactory.class);
    assertNotNull("Unwrapping to SPI class HibernateEntityManagerFactory should be ok", hibernateEntityManagerFactory);
}
Also used : HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory) Test(org.junit.Test)

Example 2 with HibernateEntityManagerFactory

use of org.hibernate.jpa.HibernateEntityManagerFactory in project hibernate-orm by hibernate.

the class MappingClassMoreThanOnceTest method testBootstrapWithClassMappedMOreThanOnce.

/**
	 * Tests that an entity manager can be created when a class is mapped more than once.
	 */
@Test
@TestForIssue(jiraKey = "HHH-8775")
public //	@FailureExpected(jiraKey = "HHH-8775")
void testBootstrapWithClassMappedMOreThanOnce() {
    Map settings = new HashMap();
    settings.put(AvailableSettings.HBXML_FILES, "org/hibernate/jpa/test/callbacks/hbmxml/ClassMappedMoreThanOnce.hbm.xml");
    final EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl(getClass().getSimpleName()), settings);
    HibernateEntityManagerFactory emf = null;
    try {
        emf = builder.build().unwrap(HibernateEntityManagerFactory.class);
    } finally {
        if (emf != null) {
            try {
                emf.close();
            } catch (Exception ignore) {
            }
        }
    }
}
Also used : BaseEntityManagerFunctionalTestCase(org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase) HashMap(java.util.HashMap) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory) Map(java.util.Map) HashMap(java.util.HashMap) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with HibernateEntityManagerFactory

use of org.hibernate.jpa.HibernateEntityManagerFactory in project wildfly by wildfly.

the class HibernateCollectionStatistics method getBaseStatistics.

private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
    if (entityManagerFactory == null) {
        return null;
    }
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics();
    }
    return null;
}
Also used : SessionFactory(org.hibernate.SessionFactory) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory)

Example 4 with HibernateEntityManagerFactory

use of org.hibernate.jpa.HibernateEntityManagerFactory in project wildfly by wildfly.

the class HibernateCollectionStatistics method getStatistics.

private CollectionStatistics getStatistics(final EntityManagerFactory entityManagerFactory, String collectionName) {
    if (entityManagerFactory == null) {
        return null;
    }
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics().getCollectionStatistics(collectionName);
    }
    return null;
}
Also used : SessionFactory(org.hibernate.SessionFactory) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory)

Example 5 with HibernateEntityManagerFactory

use of org.hibernate.jpa.HibernateEntityManagerFactory in project wildfly by wildfly.

the class HibernateEntityStatistics method getStatistics.

private org.hibernate.stat.EntityStatistics getStatistics(EntityManagerFactory entityManagerFactory, String entityName) {
    if (entityManagerFactory == null) {
        return null;
    }
    HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
    if (sessionFactory != null) {
        return sessionFactory.getStatistics().getEntityStatistics(entityName);
    }
    return null;
}
Also used : SessionFactory(org.hibernate.SessionFactory) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory)

Aggregations

HibernateEntityManagerFactory (org.hibernate.jpa.HibernateEntityManagerFactory)13 SessionFactory (org.hibernate.SessionFactory)9 Test (org.junit.Test)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)1 BaseEntityManagerFunctionalTestCase (org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase)1 Statistics (org.hibernate.stat.Statistics)1 TestForIssue (org.hibernate.testing.TestForIssue)1