Search in sources :

Example 56 with EntityManagerFactory

use of javax.persistence.EntityManagerFactory in project microservices by pwillhan.

the class EntityManagerTest method testPersist.

@Test
public void testPersist() {
    final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test");
    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    Person person = new Person();
    person.setName("Tom");
    entityManager.getTransaction().begin();
    entityManager.persist(person);
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) Test(org.junit.Test)

Example 57 with EntityManagerFactory

use of javax.persistence.EntityManagerFactory in project microservices by pwillhan.

the class App method entityManager.

private static void entityManager() {
    final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("test");
    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    final Person person = new Person();
    person.setName("Dick");
    entityManager.getTransaction().begin();
    entityManager.persist(person);
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) Person(com.company.app.model.Person)

Example 58 with EntityManagerFactory

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

the class JpaConfiguration method getMetadata.

public Metadata getMetadata() {
    if (metadata == null) {
        EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = HibernateToolsPersistenceProvider.createEntityManagerFactoryBuilder(persistenceUnit, getProperties());
        EntityManagerFactory entityManagerFactory = entityManagerFactoryBuilder.build();
        metadata = entityManagerFactoryBuilder.getMetadata();
        getProperties().putAll(entityManagerFactory.getProperties());
    }
    return metadata;
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 59 with EntityManagerFactory

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

the class SessionFactoryFacadeTest method testGetCollectionMetadata.

@Test
public void testGetCollectionMetadata() {
    Configuration configuration = new Configuration();
    configuration.addClass(Foo.class);
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Metamodel metamodel = ((EntityManagerFactory) sessionFactory).getMetamodel();
    CollectionMetadata collectionMetadata = (CollectionMetadata) ((MetamodelImplementor) metamodel).collectionPersister("org.jboss.tools.hibernate.runtime.v_5_2.internal.test.Foo.bars");
    Assert.assertSame(collectionMetadata, ((IFacade) sessionFactoryFacade.getCollectionMetadata("org.jboss.tools.hibernate.runtime.v_5_2.internal.test.Foo.bars")).getTarget());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) CollectionMetadata(org.hibernate.metadata.CollectionMetadata) ICollectionMetadata(org.jboss.tools.hibernate.runtime.spi.ICollectionMetadata) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) EntityManagerFactory(javax.persistence.EntityManagerFactory) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Metamodel(javax.persistence.metamodel.Metamodel) Test(org.junit.Test)

Example 60 with EntityManagerFactory

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

the class SessionFactoryFacadeTest method testGetClassMetadata.

@Test
public void testGetClassMetadata() {
    Configuration configuration = new Configuration();
    configuration.addClass(Foo.class);
    SessionFactory sessionFactory = configuration.buildSessionFactory(new StandardServiceRegistryBuilder().build());
    Metamodel metamodel = ((EntityManagerFactory) sessionFactory).getMetamodel();
    ClassMetadata classMetadata = (ClassMetadata) ((MetamodelImplementor) metamodel).entityPersister(Foo.class);
    ISessionFactory sessionFactoryFacade = FACADE_FACTORY.createSessionFactory(sessionFactory);
    Assert.assertSame(classMetadata, ((IFacade) sessionFactoryFacade.getClassMetadata(Foo.class)).getTarget());
    Assert.assertSame(classMetadata, ((IFacade) sessionFactoryFacade.getClassMetadata("org.jboss.tools.hibernate.runtime.v_5_2.internal.test.Foo")).getTarget());
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ClassMetadata(org.hibernate.metadata.ClassMetadata) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) EntityManagerFactory(javax.persistence.EntityManagerFactory) Foo(org.jboss.tools.hibernate.runtime.v_5_2.internal.test.Foo) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) Metamodel(javax.persistence.metamodel.Metamodel) Test(org.junit.Test)

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