Package javax.persistence

Examples of javax.persistence.EntityManager.find()


    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 );
View Full Code Here


    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 );
View Full Code Here

    }

    public String showCarDetails(String numberPlate) {
        try {
          EntityManager em = provider.getEntityManagerFactory().createEntityManager();
          this.car = em.find(Car.class, numberPlate);
          em.close();
          log.info("show car " + numberPlate + " details");
        } catch (Exception e) {
          log.warning("An exception occured while extracting " + numberPlate + " from infinispan");
          e.printStackTrace();
View Full Code Here

    removeCar("FML 23-25");
  }
 
  private void removeCar(String numberPlate) {
    EntityManager em = factory.createEntityManager();
    Car car = em.find(Car.class, numberPlate);
    em.remove(car);
    em.close();
    System.out.println("Remove Car " + numberPlate);
  }
View Full Code Here

    }

    public String removeCar(String numberPlate) {
        try {
          EntityManager em = provider.getEntityManagerFactory().createEntityManager();
          Car car = em.find(Car.class, numberPlate);
          em.remove(car);
          em.close();
            log.info("remote car " + numberPlate);
        } catch (Exception e) {
          log.warning("error whiling remote car " + numberPlate);
View Full Code Here

        System.out.println("Get Car list " + result);
  }

  private void showCarDetails(String numberPlate) {
    EntityManager em = factory.createEntityManager();
    Car car = em.find(Car.class, numberPlate);
    em.close();
    System.out.println("Show Car Details " + car);
    }

  private void addNewCar() {
View Full Code Here

    @Override
    public Person create(Bean<Person> bean, CreationalContext<Person> creationalContext) {
        // Here we use the entityManager to get the Person Instance
        EntityManager em = BeanProvider.getContextualReference(EntityManager.class);
        return em.find(Person.class, idValue);
    }
}
View Full Code Here

    // Now read it back and verify
    log.info("Reading back from database and verifying...");
    EntityTransaction readTx = em.getTransaction();
    readTx.begin();
   
    Book fellowship = em.find(Book.class, book.getId());
    Assert.assertNotNull(fellowship);
    Assert.assertEquals("Fellowship of the Ring", fellowship.getTitle());
    Assert.assertEquals("JRR", fellowship.getAuthor().getFirstName());
    Assert.assertEquals("Tolkein", fellowship.getAuthor().getLastName());
   
View Full Code Here

        em.close();
       
        em = emf.createEntityManager();
        em.getTransaction().begin();
        try {
            o = em.find(ExceptionsFromCallbacksEntity.class, oid);
            fail("find should have failed");
        } catch (CallbackTestException cte) {
            // transaction should be active but marked for rollback
            assertTrue(em.getTransaction().isActive());
            assertTrue(em.getTransaction().getRollbackOnly());
View Full Code Here

        em.getTransaction().begin();
        em.merge(deserialized);
        em.getTransaction().commit();

        em.clear();
        emp = em.find(Employee.class, id);

        assertEquals(deserialized, emp);
    }

    /**
 
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.