Package org.springframework.orm.jpa.domain

Examples of org.springframework.orm.jpa.domain.Person


    setComplete();
  }
 
  public void doInstantiateAndSave(EntityManager em) {
    testStateClean();
    Person p = new Person();
   
    p.setFirstName("Tony");
    p.setLastName("Blair");
    em.persist(p);
   
    em.flush();
    assertEquals("1 row must have been inserted",
        1, countRowsInTable("person"));
View Full Code Here


   
    assertFalse(em.getTransaction().isActive());
   
    startNewTransaction();
    // Call any method: should cause automatic tx invocation
    assertFalse(em.contains(new Person()));
   
    assertFalse(em.getTransaction().isActive());
    em.joinTransaction();
   
    assertTrue(em.getTransaction().isActive());
View Full Code Here

  }

  @ExpectedException(EntityNotFoundException.class)
  public void testGetReferenceWhenNoRow() {
    // Fails here with TopLink
    Person notThere = sharedEntityManager.getReference(Person.class, 666);
   
    // We may get here (as with Hibernate).
    // Either behaviour is
    // valid--throw exception on first access
    // or on getReference itself
    notThere.getFirstName();
  }
View Full Code Here

    notThere.getFirstName();
  }

  public void testLazyLoading() {
    try {
      Person tony = new Person();
      tony.setFirstName("Tony");
      tony.setLastName("Blair");
      tony.setDriversLicense(new DriversLicense("8439DK"));
      sharedEntityManager.persist(tony);
      setComplete();
      endTransaction();
     
      startNewTransaction();
      sharedEntityManager.clear();
      Person newTony = entityManagerFactory.createEntityManager().getReference(Person.class, tony.getId());
      assertNotSame(newTony, tony);
      endTransaction();
       
      assertNotNull(newTony.getDriversLicense());
     
      newTony.getDriversLicense().getSerialNumber();
    }
    finally {
      deleteFromTables(new String[] { "person", "drivers_license" });
      //setComplete();
    }
View Full Code Here

  }

  protected void testInstantiateAndSave(EntityManager em) {
    assertEquals("Should be no people from previous transactions",
        0, countRowsInTable("person"));
    Person p = new Person();
    p.setFirstName("Tony");
    p.setLastName("Blair");
    em.persist(p);
   
    em.flush();
    assertEquals("1 row must have been inserted", 1, countRowsInTable("person"));
  }
View Full Code Here

  public void testSavepoint() {
    TransactionTemplate tt = new TransactionTemplate(transactionManager);
    tt.setPropagationBehavior(TransactionTemplate.PROPAGATION_NESTED);
    tt.execute(new TransactionCallbackWithoutResult() {
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        Person tony = new Person();
        tony.setFirstName("Tony");
        sharedEntityManager.merge(tony);
        Query q = sharedEntityManager.createQuery("select p from Person as p");
        q.setFlushMode(FlushModeType.COMMIT);
        List<Person> people = q.getResultList();
        assertEquals(1, people.size());
View Full Code Here

  }
 
  public void doInstantiateAndSave(EntityManager em) {
    assertEquals("Should be no people from previous transactions",
        0, countRowsInTable("person"));
    Person p = new Person();
   
    p.setFirstName("Tony");
    p.setLastName("Blair");
    em.persist(p);
   
    em.flush();
    assertEquals("1 row must have been inserted",
        1, countRowsInTable("person"));
View Full Code Here

   
    //assertFalse(em.getTransaction().isActive());
   
    startNewTransaction();
    // Call any method: should cause automatic tx invocation
    assertFalse(em.contains(new Person()));
    //assertTrue(em.getTransaction().isActive());
   
    doInstantiateAndSave(em);
    setComplete();
    endTransaction()// Should rollback
View Full Code Here

    }
  }

  public void testGetReferenceWhenNoRow() {
    try {
      Person notThere = sharedEntityManager.getReference(Person.class, 666);

      // We may get here (as with Hibernate).
      // Either behaviour is valid: throw exception on first access
      // or on getReference itself.
      notThere.getFirstName();
      fail("Should have thrown an EntityNotFoundException");
    }
    catch (EntityNotFoundException e) {
      /* expected */
    }
 
View Full Code Here

    }
  }

  public void testLazyLoading() {
    try {
      Person tony = new Person();
      tony.setFirstName("Tony");
      tony.setLastName("Blair");
      tony.setDriversLicense(new DriversLicense("8439DK"));
      sharedEntityManager.persist(tony);
      setComplete();
      endTransaction();

      startNewTransaction();
      sharedEntityManager.clear();
      Person newTony = entityManagerFactory.createEntityManager().getReference(Person.class, tony.getId());
      assertNotSame(newTony, tony);
      endTransaction();

      assertNotNull(newTony.getDriversLicense());

      newTony.getDriversLicense().getSerialNumber();
    }
    finally {
      deleteFromTables("person", "drivers_license");
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.orm.jpa.domain.Person

Copyright © 2018 www.massapicom. 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.