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