Examples of EntityManagerFactory


Examples of javax.persistence.EntityManagerFactory

  public PackagingRule packaging = new PackagingRule( "persistencexml/jpajtastandalone.xml", Hero.class, SuperHero.class );

  @Test
  public void testJPAPolymorphicFind() throws Exception {

    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone",
        TestHelper.getEnvironmentProperties() );

    TransactionManager transactionManager = extractJBossTransactionManager( emf );

    transactionManager.begin();
    final EntityManager em = emf.createEntityManager();
    Hero h = new Hero();
    h.setName( "Spartacus" );
    em.persist( h );
    SuperHero sh = new SuperHero();
    sh.setName( "Batman" );
    sh.setSpecialPower( "Technology and samurai techniques" );
    em.persist( sh );
    transactionManager.commit();

    em.clear();

    transactionManager.begin();
    Hero lh = em.find( Hero.class, h.getName() );
    assertThat( lh ).isNotNull();
    assertThat( lh ).isInstanceOf( Hero.class );
    Hero lsh = em.find( Hero.class, sh.getName() );
    assertThat( lsh ).isNotNull();
    assertThat( lsh ).isInstanceOf( SuperHero.class );
    em.remove( lh );
    em.remove( lsh );

    transactionManager.commit();

    em.close();

    dropSchemaAndDatabase( emf );
    emf.close();
  }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

    /**
     * Flush search indexes, to be done after a reindex() or reindexAll() operation
     */
    public void flushSearchIndexes() {
        EntityManagerFactory entityManagerFactory = (EntityManagerFactory) applicationContext.getBean("entityManagerFactory");
        FullTextEntityManager fullTextEntityMgr = Search.getFullTextEntityManager(entityManagerFactory.createEntityManager());
        fullTextEntityMgr.flushToIndexes();
    }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

        EmbeddedDataSource ds = new EmbeddedDataSource();
        ds.setDatabaseName("target/test");
        ds.setCreateDatabase("create");
        ic.bind("osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/derbyds)", ds);
        PersonServiceImpl personService = new PersonServiceImpl();
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("personTest", System.getProperties());
        EntityManager em = emf.createEntityManager();
        personService.setEntityManager(em);
        em.getTransaction().begin();
        personService.deleteAll();
        personService.add(new Person("Christian Schneider", "@schneider_chris"));
        em.getTransaction().commit();
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

        EmbeddedDataSource ds = new EmbeddedDataSource();
        ds.setDatabaseName("target/test");
        ds.setCreateDatabase("create");
        ic.bind("osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/derbyds)", ds);
        PersonServiceImpl personService = new PersonServiceImpl();
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("personTest", System.getProperties());
        EntityManager em = emf.createEntityManager();
        personService.setEntityManager(em);
        em.getTransaction().begin();
        personService.deleteAll();
        personService.add(new Person("Christian Schneider", "@schneider_chris"));
        em.getTransaction().commit();
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

    log.info("Resetting database state");
    resetDatabaseState();
  }

  private static void resetDatabaseState() {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("exampleHibernateJPA");
   
    EntityManager em = emf.createEntityManager();
   
    log.info("Creating and persisting entity...");
    EntityTransaction tx = em.getTransaction();
    tx.begin();
   
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

  @Test
  public void testDatabaseSaveAndRetrieve() {
    log.info("Running testDatabaseSaveAndRetrieve");
   
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("exampleHibernateJPA");
   
    EntityManager em = emf.createEntityManager();
   
    log.info("Creating and persisting entity...");
    EntityTransaction tx = em.getTransaction();
    tx.begin();
   
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

      }
   }
  
   public EntityManagerFactory getEntityManagerFactoryFromJndiOrValueBinding()
   {
      EntityManagerFactory result = null;
      //first try to find it via the value binding
      if (entityManagerFactory!=null)
      {
         result = entityManagerFactory.getValue();
      }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

        context, logger, GENERATED_PACKAGE, GENERATED_CLASS_NAME);
  }

  @Override
  protected String generate(final TreeLogger logger, final GeneratorContext context) {
    EntityManagerFactory emf = createHibernateEntityManagerFactory(logger, context);
    try {
      return generateEntityManagerFactoryClass(logger, context, emf);
    }
    finally {
      emf.close();
    }
  }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

  @Override
  public String generate(TreeLogger logger, GeneratorContext context,
          String typeName) throws UnableToCompleteException {

    GWTUtil.populateMetaClassFactoryFromTypeOracle(context, logger);
    EntityManagerFactory emf = createHibernateEntityManagerFactory(logger, context);
    try {
      final ClassStructureBuilder<?> classBuilder = generateEntityManagerClass(
              logger, context, emf);
      return classBuilder.getClassDefinition().getFullyQualifiedName();
    }
    finally {
      emf.close();
    }
  }
View Full Code Here

Examples of javax.persistence.EntityManagerFactory

    }

    public void test() {
        emf.close();

        EntityManagerFactory oldEmf = emf;
        emf = createEMF(AddressEntity.class, AddressPk.class, MyUserEntity.class);
        // ensure that we get a fresh emf
        assertNotEquals(oldEmf, emf);
        emf.getCriteriaBuilder();
        EntityManager em = emf.createEntityManager();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.