Package javax.persistence

Examples of javax.persistence.EntityManager.clear()


    video.setDirector( "Wes Craven" );
    video.setName( "Scream" );
    em.persist( video );
    getTransactionManager().commit();

    em.clear();

    getTransactionManager().begin();
    music = em.find( Music.class, music.getId() );
    assertThat( music ).isNotNull();
    assertThat( music.getName() ).isEqualTo( "Variations Sur Marilou" );
View Full Code Here


        List<Department> ds =
            em.createQuery(
                "SELECT DISTINCT d FROM Department d LEFT JOIN FETCH d.employees " + "LEFT JOIN FETCH d.employee2s "
                    + "WHERE d.deptno = 10").getResultList();
        System.out.println("-- testJPQLTwoFetch -----");
        em.clear();
        Assert.assertEquals(1, ds.size());
        for (Department x : ds) {
            Assert.assertNotNull(x.getEmployees());
            Assert.assertEquals(2, x.getEmployees().size());
            Assert.assertNotNull(x.getEmployee2s());
View Full Code Here

        Root<Department> d = q.from(Department.class);
        q.where(cb.equal(d.get(Department_.deptno), 20)).select(d);

        List<Department> ds = em.createQuery(q).getResultList();
        System.out.println("-- testCriteriaAPINoFetch -----");
        em.clear();
        Assert.assertEquals(1, ds.size());
        for (Department x : ds) {
            Assert.assertNull(x.getEmployees());
            Assert.assertNull(x.getEmployee2s());
            System.out.println(x);
View Full Code Here

        d.fetch(Department_.employees, JoinType.LEFT);
        q.where(cb.equal(d.get(Department_.deptno), 20)).select(d).distinct(true);

        List<Department> ds = em.createQuery(q).getResultList();
        System.out.println("-- testCriteriaAPIOneFetch -----");
        em.clear();
        Assert.assertEquals(1, ds.size());
        for (Department x : ds) {
            Assert.assertNotNull(x.getEmployees());
            Assert.assertEquals(2, x.getEmployees().size());
            Assert.assertNull(x.getEmployee2s());
View Full Code Here

        d.fetch(Department_.employee2s, JoinType.LEFT);
        q.where(cb.equal(d.get(Department_.deptno), 20)).select(d).distinct(true);

        List<Department> ds = em.createQuery(q).getResultList();
        System.out.println("-- testCriteriaAPITwoFetch -----");
        em.clear();
        Assert.assertEquals(1, ds.size());
        for (Department x : ds) {
            Assert.assertNotNull(x.getEmployees());
            Assert.assertEquals(2, x.getEmployees().size());
            Assert.assertNotNull(x.getEmployee2s());
View Full Code Here

            t.setSomeInt(t.getSomeInt() + 1);
            t = em.merge(t);

            tx.commit();
            // If this clear is removed the test works fine.
            em.clear();

            // Lets say at this point the 'in-memory' timestamp is: 2014-01-22 07:22:11.548778567.  What we
            // actually sent to the DB (via the previous merge) is by default rounded (see DBDictionary.setTimestamp)
            // to the nearest millisecond on Oracle (see DBDictionary.datePrecision) and nearest microsecond on
            // DB2 (see DB2Dictionary.datePrecision) when sending the value to the db.
View Full Code Here

    Employee employee = new Employee( "Alex", "EMPLOYER" );
    em.persist( employee );
    tm.commit();

    em.clear();

    tm.begin();
    CommunityMember lh = em.find( CommunityMember.class, member.name );
    assertThat( lh ).isNotNull();
    assertThat( lh ).isInstanceOf( CommunityMember.class );
View Full Code Here

    EntityManager em = getPersistenceContext(false);
    try {
      return em.contains(arg0);
    } finally {
      if(em == detachedManager)
        em.clear();
    }
  }

  public Query createNamedQuery(String arg0)
  {
View Full Code Here

    EntityManager em = getPersistenceContext(false);
    try {
      return em.createNamedQuery(arg0);
    } finally {
      if(em == detachedManager)
        em.clear();
    }
  }

  public Query createNativeQuery(String arg0)
  {
View Full Code Here

    EntityManager em = getPersistenceContext(false);
    try {
      return em.createNativeQuery(arg0);
    } finally {
      if(em == detachedManager)
        em.clear();
    }
  }

  @SuppressWarnings("unchecked")
  public Query createNativeQuery(String arg0, Class arg1)
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.