Program: 65695
Project: 65695
Buggy source:
public void testComplexMultitenantQueries(){
  EntityManager em=createEntityManager(MULTI_TENANT_PU_123);
  try {
    clearCache(MULTI_TENANT_PU_123);
    em.clear();
    try {
      Query q=em.createQuery("String_Node_Str");
      SubCapo subCapo=new SubCapo();
      subCapo.setId(capo123Id);
      q.setParameter(1,subCapo);
      List<Soldier> soldiers=q.getResultList();
      assertTrue("String_Node_Str" + soldiers.size() + "String_Node_Str",soldiers.size() == 1);
      assertTrue("String_Node_Str",soldiers.get(0).isSoldier());
      assertTrue("String_Node_Str",soldiers.get(0).getId() == soldier123Id);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      TypedQuery<MafiaFamily> q=em.createQuery("String_Node_Str",MafiaFamily.class);
      q.setHint(QueryHints.FETCH,"String_Node_Str");
      q.getResultList();
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      TypedQuery<MafiaFamily> q=em.createQuery("String_Node_Str",MafiaFamily.class);
      q.setHint(QueryHints.FETCH,"String_Node_Str");
      q.getResultList();
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      TypedQuery<MafiaFamily> query=em.createQuery("String_Node_Str",MafiaFamily.class);
      query.setHint(QueryHints.BATCH,"String_Node_Str");
      List<MafiaFamily> families=query.getResultList();
      assertTrue("String_Node_Str" + families.size() + "String_Node_Str",families.size() == 1);
      int size=families.get(0).getMafiosos().size();
      assertTrue("String_Node_Str" + size + "String_Node_Str",size == 6);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      Query query=em.createQuery("String_Node_Str",MafiaFamily.class);
      List results=query.getResultList();
      int size=results.size();
      assertTrue("String_Node_Str" + size + "String_Node_Str",size == 6);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      beginTransaction(em);
      int contracts=em.createNamedQuery("String_Node_Str").getResultList().size();
      int deletes=em.createNamedQuery("String_Node_Str").executeUpdate();
      assertTrue("String_Node_Str" + deletes + "String_Node_Str"+ contracts+ "String_Node_Str",deletes == 2);
      commitTransaction(em);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    if (getServerSession(MULTI_TENANT_PU).getPlatform().isSymfoware()) {
      getServerSession(MULTI_TENANT_PU).logMessage("String_Node_Str" + "String_Node_Str");
    }
 else {
      try {
        beginTransaction(em);
        this.getServerSession(MULTI_TENANT_PU).setLogLevel(0);
        List<MafiaFamily> allFamilies=em.createNamedQuery("String_Node_Str").getResultList();
        int families=allFamilies.size();
        assertTrue("String_Node_Str" + families + "String_Node_Str",families == 1);
        Query deleteQuery=em.createNamedQuery("String_Node_Str");
        deleteQuery.setHint(QueryHints.ALLOW_NATIVE_SQL_QUERY,true);
        int deletes=deleteQuery.executeUpdate();
        assertTrue("String_Node_Str" + deletes + "String_Node_Str"+ families+ "String_Node_Str",deletes == 1);
        commitTransaction(em);
      }
 catch (      Exception e) {
        fail("String_Node_Str" + e);
      }
      EntityManager em007=createEntityManager(MULTI_TENANT_PU);
      try {
        beginTransaction(em);
        List<MafiaFamily> families=em007.createNativeQuery("String_Node_Str",MafiaFamily.class).getResultList();
        assertTrue("String_Node_Str" + families.size() + "String_Node_Str",families.size() == 2);
        commitTransaction(em);
        beginTransaction(em007);
        em007.setProperty("String_Node_Str","String_Node_Str");
        em007.setProperty(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT,"String_Node_Str");
        MafiaFamily family=em007.find(MafiaFamily.class,family007);
        assertFalse("String_Node_Str",family.getTags().isEmpty());
        assertFalse("String_Node_Str",family.getRevenue() == null);
        commitTransaction(em007);
      }
 catch (      Exception e) {
        fail("String_Node_Str" + e);
      }
 finally {
        if (isTransactionActive(em007)) {
          rollbackTransaction(em007);
        }
        closeEntityManager(em007);
      }
    }
  }
  finally {
    if (isTransactionActive(em)) {
      rollbackTransaction(em);
    }
    closeEntityManager(em);
  }
}

Fixed version (ground truth):
public void testComplexMultitenantQueries(){
  EntityManager em=createEntityManager(MULTI_TENANT_PU_123);
  try {
    clearCache(MULTI_TENANT_PU_123);
    em.clear();
    try {
      Query q=em.createQuery("String_Node_Str");
      SubCapo subCapo=new SubCapo();
      subCapo.setId(capo123Id);
      q.setParameter(1,subCapo);
      List<Soldier> soldiers=q.getResultList();
      assertTrue("String_Node_Str" + soldiers.size() + "String_Node_Str",soldiers.size() == 1);
      assertTrue("String_Node_Str",soldiers.get(0).isSoldier());
      assertTrue("String_Node_Str",soldiers.get(0).getId() == soldier123Id);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      TypedQuery<MafiaFamily> q=em.createQuery("String_Node_Str",MafiaFamily.class);
      q.setHint(QueryHints.FETCH,"String_Node_Str");
      q.getResultList();
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      TypedQuery<MafiaFamily> q=em.createQuery("String_Node_Str",MafiaFamily.class);
      q.setHint(QueryHints.FETCH,"String_Node_Str");
      q.getResultList();
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      TypedQuery<MafiaFamily> query=em.createQuery("String_Node_Str",MafiaFamily.class);
      query.setHint(QueryHints.BATCH,"String_Node_Str");
      List<MafiaFamily> families=query.getResultList();
      assertTrue("String_Node_Str" + families.size() + "String_Node_Str",families.size() == 1);
      int size=families.get(0).getMafiosos().size();
      assertTrue("String_Node_Str" + size + "String_Node_Str",size == 6);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      Query query=em.createQuery("String_Node_Str",MafiaFamily.class);
      List results=query.getResultList();
      int size=results.size();
      assertTrue("String_Node_Str" + size + "String_Node_Str",size == 6);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    try {
      beginTransaction(em);
      int contracts=em.createNamedQuery("String_Node_Str").getResultList().size();
      int deletes=em.createNamedQuery("String_Node_Str").executeUpdate();
      assertTrue("String_Node_Str" + deletes + "String_Node_Str"+ contracts+ "String_Node_Str",deletes == 2);
      commitTransaction(em);
    }
 catch (    Exception e) {
      fail("String_Node_Str" + e);
    }
    if (getServerSession(MULTI_TENANT_PU).getPlatform().isSymfoware()) {
      getServerSession(MULTI_TENANT_PU).logMessage("String_Node_Str" + "String_Node_Str");
    }
 else {
      try {
        beginTransaction(em);
        List<MafiaFamily> allFamilies=em.createNamedQuery("String_Node_Str").getResultList();
        int families=allFamilies.size();
        assertTrue("String_Node_Str" + families + "String_Node_Str",families == 1);
        Query deleteQuery=em.createNamedQuery("String_Node_Str");
        deleteQuery.setHint(QueryHints.ALLOW_NATIVE_SQL_QUERY,true);
        int deletes=deleteQuery.executeUpdate();
        assertTrue("String_Node_Str" + deletes + "String_Node_Str"+ families+ "String_Node_Str",deletes == 1);
        commitTransaction(em);
      }
 catch (      Exception e) {
        fail("String_Node_Str" + e);
      }
      EntityManager em007=createEntityManager(MULTI_TENANT_PU);
      try {
        List<MafiaFamily> families=em007.createNativeQuery("String_Node_Str",MafiaFamily.class).getResultList();
        assertTrue("String_Node_Str" + families.size() + "String_Node_Str",families.size() == 2);
        clearCache(MULTI_TENANT_PU);
        em007.clear();
        beginTransaction(em007);
        em007.setProperty("String_Node_Str","String_Node_Str");
        em007.setProperty(EntityManagerProperties.MULTITENANT_PROPERTY_DEFAULT,"String_Node_Str");
        MafiaFamily family=em007.find(MafiaFamily.class,family007);
        assertFalse("String_Node_Str",family.getTags().isEmpty());
        assertFalse("String_Node_Str",family.getRevenue() == null);
        commitTransaction(em007);
      }
 catch (      Exception e) {
        fail("String_Node_Str" + e);
      }
 finally {
        if (isTransactionActive(em007)) {
          rollbackTransaction(em007);
        }
        closeEntityManager(em007);
      }
    }
  }
  finally {
    if (isTransactionActive(em)) {
      rollbackTransaction(em);
    }
    closeEntityManager(em);
  }
}