Package javax.persistence

Examples of javax.persistence.EntityManager.detach()


  public void detach(Object entity)
  {
    EntityManager em = getCurrent();
   
    if (em != null) {
      em.detach(entity);
      return;
    }
   
    em = createEntityManager();
   
View Full Code Here


    }
   
    em = createEntityManager();
   
    try {
      em.detach(entity);
    } finally {
      freeEntityManager(em);
    }
  }
View Full Code Here

  }

  private EntityManager delete(Object... entities) {
    EntityManager em = createEntityManager();
    for ( Object object : entities ) {
      em.detach( object );
    }
    return em;
  }

  private void commit() throws Exception {
View Full Code Here

        sql.clear();
        List<Employee> emps = em.createQuery(query, Employee.class).getResultList();
        Assert.assertEquals(4, emps.size());
        for (Employee emp : emps) {
            em.detach(emp);

            Assert.assertNotNull(emp.getDept());
            Assert.assertEquals(2, emp.getDept().getEmployees().size());
        }
        em.close();
View Full Code Here

  }

  private EntityManager delete(Object... entities) {
    EntityManager em = createEntityManager();
    for ( Object object : entities ) {
      em.detach( object );
    }
    return em;
  }

  private void begin() throws NotSupportedException, SystemException, Exception {
View Full Code Here

  {
    EntityManager em = getPersistenceContext(false);
    //The detatched manager auto-detaches everything, so only
    //detach from a "real" entity manager
    if(em != detachedManager)
      em.detach(arg0);
  }

  public <T> T find(Class<T> arg0, Object arg1, Map<String, Object> arg2)
  {
    EntityManager em = getPersistenceContext(false);
View Full Code Here

    em.getTransaction().begin();
    mouth = em.find( Mouth.class, mouth.id );
    assertNotNull( mouth );
    assertEquals( 1, mouth.teeth.size() );
    tooth = mouth.teeth.iterator().next();
    em.detach( mouth );
    assertFalse( em.contains( tooth ) );
    em.getTransaction().commit();
    em.close();

    em = getOrCreateEntityManager();
View Full Code Here

    EntityManager em = mEmf.createEntityManager();
    NoteList notesList = null;
    try{
      notesList = em.find(NoteList.class, key);
      notesList.getNotes(); // lazy loading
      em.detach(notesList);
    } catch (Exception e) {
      e.printStackTrace();
      throw new DAOException();
    } finally {
      em.close();
View Full Code Here

            Recliner r2 = em.find(Recliner.class, recId);
            assertNotNull("Find returned null object", r2);
            assertTrue(selectContains("REC_TABLE", _sql, "REC_STYLE", "RECID_ID", "RECID_COLOR"));
            assertFalse(selectContains("REC_TABLE", _sql, "GUY_HEIGHT", "GUY_WEIGHT", "GUY_NAME",
                "BH_DIAMETER", "BH_DEPTH"));
            em.detach(r2);
            // Lazy embeds should be null after detach.
            assertNull("Embedded field guy is null before getter is called", r2.getGuy());
            assertNull("Embedded field holder is null before getter is called", r2.getHolder());

            // verify lazy embeds will load on access post-detach and merge
View Full Code Here

  {
    EntityManager em = getPersistenceContext(false);
    //The detatched manager auto-detaches everything, so only
    //detach from a "real" entity manager
    if(em != detachedManager)
      em.detach(arg0);
  }

  public <T> T find(Class<T> arg0, Object arg1, Map<String, Object> arg2)
  {
    EntityManager em = getPersistenceContext(false);
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.