Program: 176986
Project: 176986
Buggy source:
/** 
 * Saves an object graph to persistence stores. An object graph contains a parent entity and one or more child entities at a time. There are other attributes too that represent their relationship. 
 * @param objectGraph the object graph
 */
private void saveGraph(EntitySaveGraph objectGraph){
  Object parentEntity=objectGraph.getParentEntity();
  EntityMetadata metadata=getMetadata(objectGraph.getParentClass());
  List<EntitySaveGraph> relationGraphs=null;
  if (objectGraph.isIsswapped() && !metadata.getRelations().isEmpty() && !objectGraph.getChildClass().equals(objectGraph.getParentClass())) {
    relationGraphs=getGraph(parentEntity,metadata);
    for (    EntitySaveGraph g : relationGraphs) {
      if (!(objectGraph.getChildClass().equals(g.getParentClass()) || objectGraph.getChildClass().equals(g.getChildClass()))) {
        saveGraph(g);
      }
    }
  }
  if (parentEntity != null) {
    objectGraph.setParentId(getId(parentEntity,metadata));
    if (getSession().lookup(objectGraph.getParentClass(),objectGraph.getParentId()) == null) {
      Client pClient=getClient(metadata);
      pClient.persist(objectGraph,metadata);
      session.store(objectGraph.getParentId(),objectGraph.getParentEntity());
    }
  }
  Object childEntity=objectGraph.getChildEntity();
  if (objectGraph.getParentEntity() != null && childEntity != null) {
    persistChildEntity(objectGraph,childEntity);
  }
  for (  Relation relation : metadata.getRelations()) {
    if (relation.isRelatedViaJoinTable()) {
      JoinTableMetadata jtMetadata=relation.getJoinTableMetadata();
      String joinTableName=jtMetadata.getJoinTableName();
      Set<String> joinColumns=jtMetadata.getJoinColumns();
      Set<String> inverseJoinColumns=jtMetadata.getInverseJoinColumns();
      String joinColumnName=(String)joinColumns.toArray()[0];
      String inverseJoinColumnName=(String)inverseJoinColumns.toArray()[0];
      EntityMetadata relMetadata=getMetadata(objectGraph.getChildClass());
      Client pClient=getClient(metadata);
      pClient.persistJoinTable(joinTableName,joinColumnName,inverseJoinColumnName,relMetadata,objectGraph);
    }
  }
}

Fixed version (ground truth):
/** 
 * Saves an object graph to persistence stores. An object graph contains a parent entity and one or more child entities at a time. There are other attributes too that represent their relationship. 
 * @param objectGraph the object graph
 */
private void saveGraph(EntitySaveGraph objectGraph){
  Object parentEntity=objectGraph.getParentEntity();
  EntityMetadata metadata=getMetadata(objectGraph.getParentClass());
  List<EntitySaveGraph> relationGraphs=null;
  if (objectGraph.isIsswapped() && !metadata.getRelations().isEmpty() && !objectGraph.getChildClass().equals(objectGraph.getParentClass())&& parentEntity != null) {
    relationGraphs=getGraph(parentEntity,metadata);
    for (    EntitySaveGraph g : relationGraphs) {
      if (!(objectGraph.getChildClass().equals(g.getParentClass()) || objectGraph.getChildClass().equals(g.getChildClass()))) {
        saveGraph(g);
      }
    }
  }
  if (parentEntity != null) {
    objectGraph.setParentId(getId(parentEntity,metadata));
    if (getSession().lookup(objectGraph.getParentClass(),objectGraph.getParentId()) == null) {
      Client pClient=getClient(metadata);
      pClient.persist(objectGraph,metadata);
      session.store(objectGraph.getParentId(),objectGraph.getParentEntity());
    }
  }
  Object childEntity=objectGraph.getChildEntity();
  if (objectGraph.getParentEntity() != null && childEntity != null) {
    persistChildEntity(objectGraph,childEntity);
  }
  for (  Relation relation : metadata.getRelations()) {
    if (relation.isRelatedViaJoinTable()) {
      JoinTableMetadata jtMetadata=relation.getJoinTableMetadata();
      String joinTableName=jtMetadata.getJoinTableName();
      Set<String> joinColumns=jtMetadata.getJoinColumns();
      Set<String> inverseJoinColumns=jtMetadata.getInverseJoinColumns();
      String joinColumnName=(String)joinColumns.toArray()[0];
      String inverseJoinColumnName=(String)inverseJoinColumns.toArray()[0];
      EntityMetadata relMetadata=getMetadata(relation.getTargetEntity());
      Object child=objectGraph.getChildEntity();
      Client pClient=getClient(metadata);
      pClient.persistJoinTable(joinTableName,joinColumnName,inverseJoinColumnName,relMetadata,objectGraph.getParentId(),child);
    }
  }
}