Example usage for javax.persistence EntityManagerFactory createEntityManager

List of usage examples for javax.persistence EntityManagerFactory createEntityManager

Introduction

In this page you can find the example usage for javax.persistence EntityManagerFactory createEntityManager.

Prototype

public EntityManager createEntityManager();

Source Link

Document

Create a new application-managed EntityManager.

Usage

From source file:org.axiom_tools.storage.PersistenceContext.java

@Bean
public JpaRepositoryFactory repositoryFactory(EntityManagerFactory emf) {
    return new JpaRepositoryFactory(emf.createEntityManager());
}

From source file:org.apache.shindig.social.opensocial.jpa.hibernate.Bootstrap.java

public void init(String unitName) {

    Map<String, String> properties = Maps.newHashMap();

    LOG.info("Starting connection manager with properties " + properties);

    EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(unitName, properties);
    entityManager = emFactory.createEntityManager();
}

From source file:test.unit.be.fedict.eid.dss.entity.PersistenceTest.java

@Before
public void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Ejb3Configuration configuration = new Ejb3Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    configuration.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    configuration.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:beta");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");

    configuration.addAnnotatedClass(AdministratorEntity.class);
    configuration.addAnnotatedClass(ConfigPropertyEntity.class);
    configuration.addAnnotatedClass(DocumentEntity.class);
    configuration.addAnnotatedClass(RPEntity.class);
    configuration.addAnnotatedClass(AccountingEntity.class);

    EntityManagerFactory entityManagerFactory = configuration.buildEntityManagerFactory();

    this.entityManager = entityManagerFactory.createEntityManager();
    this.entityManager.getTransaction().begin();
}

From source file:org.openejb.persistence.OpenJpaProviderTest.java

public void testOpenJpaProvider() throws Exception {
    System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, "org.openejb.persistence");

    PersistenceDeployer deployer = new PersistenceDeployer(new TestDataSourceResolver());

    Map<String, EntityManagerFactory> map = deployer.deploy(Thread.currentThread().getContextClassLoader());

    EntityManagerFactory emf = map.get("openjpa-test-unit");
    assertNotNull("EntityManagerFactory", emf);

    EntityManager em = emf.createEntityManager();
    assertNotNull("EntityManager", em);

    em.getTransaction().begin();//from  w w w . ja  v a  2 s  .  com
    em.persist(new AllFieldTypes());
    em.getTransaction().commit();
    em.close();

    em = emf.createEntityManager();
    em.getTransaction().begin();
    em.createQuery("delete from AllFieldTypes").executeUpdate();
    em.getTransaction().commit();
    em.close();
    emf.close();
}

From source file:test.unit.be.fedict.eid.idp.entity.PersistenceTest.java

@Before
public void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Ejb3Configuration configuration = new Ejb3Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    configuration.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    configuration.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:beta");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");

    configuration.addAnnotatedClass(AdministratorEntity.class);
    configuration.addAnnotatedClass(ConfigPropertyEntity.class);
    configuration.addAnnotatedClass(AppletConfigEntity.class);

    configuration.addAnnotatedClass(AttributeProtocolUriEntity.class);
    configuration.addAnnotatedClass(AttributeEntity.class);
    configuration.addAnnotatedClass(RPEntity.class);
    configuration.addAnnotatedClass(RPAttributeEntity.class);

    configuration.addAnnotatedClass(AccountingEntity.class);

    EntityManagerFactory entityManagerFactory = configuration.buildEntityManagerFactory();

    this.entityManager = entityManagerFactory.createEntityManager();
    this.entityManager.getTransaction().begin();
}

From source file:com.appdynamicspilot.persistence.CartPersistence.java

/**
 * EntityManager instance/*from   ww w .j  ava 2 s  . co m*/
 */
private EntityManager findEntityManger() {
    EntityManagerHolder holder = (EntityManagerHolder) SpringContext.getBean("entityManagerHolder");
    EntityManagerFactory emf = holder.getEntityManagerFactory();
    return emf.createEntityManager();
}

From source file:ro.allevo.fintpws.security.CustomUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

    EntityManagerFactory configEntityManagerFactory = Persistence
            .createEntityManagerFactory(ApiResource.PERSISTENCE_UNITNAME_CONFIG);
    EntityManager emc = configEntityManagerFactory.createEntityManager();

    final TypedQuery<UserEntity> query = emc.createNamedQuery("UserEntity.findByUsername", UserEntity.class);

    final java.util.List<UserEntity> results = query.setParameter("username", username).getResultList();

    if (!results.isEmpty()) {
        return results.get(0);
    }/*from w w w  .j a  v a  2  s  .c o  m*/
    return null;

}

From source file:de.hska.ld.core.config.PersistenceConfig.java

@Bean
@Primary
public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
    return entityManagerFactory.createEntityManager();
}

From source file:test.unit.be.fedict.eid.dss.ConfigurationBeanTest.java

@Before
public void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Ejb3Configuration configuration = new Ejb3Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    configuration.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
    configuration.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:beta");
    configuration.setProperty("hibernate.hbm2ddl.auto", "create");

    configuration.addAnnotatedClass(ConfigPropertyEntity.class);

    EntityManagerFactory entityManagerFactory = configuration.buildEntityManagerFactory();

    this.entityManager = entityManagerFactory.createEntityManager();
    this.entityManager.getTransaction().begin();

    this.testedInstance = new ConfigurationBean();
    Field[] beanFields = ConfigurationBean.class.getDeclaredFields();
    for (Field beanField : beanFields) {
        if (null == beanField.getAnnotation(PersistenceContext.class)) {
            continue;
        }//  w w  w.j  a v a 2  s . c o m
        beanField.setAccessible(true);
        beanField.set(this.testedInstance, this.entityManager);
    }
}

From source file:com.romb.hashfon.helper.Helper.java

public EntityManager getEntityManager() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.romb_hashfon_war_1.0PU");
    EntityManager ecm = emf.createEntityManager();
    return ecm;/* w  ww .  java 2s .  c om*/
}