Program: 177014
Project: 177014
Buggy source:
/** 
 * Find.
 * @param < E > the element type
 * @param entityClass the entity class
 * @param primaryKey the primary key
 * @return the e
 */
public <E>E find(Class<E> entityClass,Object primaryKey){
  try {
    E e=getSession().lookup(entityClass,primaryKey);
    isRelationViaJoinTable=false;
    if (null != e) {
      log.debug(entityClass.getName() + "String_Node_Str" + primaryKey+ "String_Node_Str");
      return e;
    }
    EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entityClass,getPersistenceUnits());
    Client client=getClient(entityMetadata);
    List<EntitySaveGraph> objectGraphs=getGraph(entityMetadata.getEntityClazz().newInstance(),entityMetadata);
    Map<Boolean,List<String>> relations=getRelations(objectGraphs,entityMetadata.getEntityClazz());
    EntityReader reader=getReader(client);
    List<String> relationNames=relations.values().iterator().next();
    String rowKey=primaryKey + "String_Node_Str";
    EnhanceEntity enhanceEntity=reader.findById(rowKey,entityMetadata,relationNames,client);
    Map<Object,Object> relationalValues=new HashMap<Object,Object>();
    E entity=(E)enhanceEntity.getEntity();
    if (relationNames.isEmpty() && !entityMetadata.isRelationViaJoinTable()) {
      return entity;
    }
 else {
      entity=(E)reader.computeGraph(enhanceEntity,objectGraphs,relationalValues,client,entityMetadata,this);
    }
    boolean isCacheableToL2=entityMetadata.isCacheable();
    getSession().store(primaryKey,entity,isCacheableToL2);
    return entity;
  }
 catch (  Exception exception) {
    exception.printStackTrace();
    throw new PersistenceException(exception);
  }
}

Fixed version (ground truth):
/** 
 * Find.
 * @param < E > the element type
 * @param entityClass the entity class
 * @param primaryKey the primary key
 * @return the e
 */
public <E>E find(Class<E> entityClass,Object primaryKey){
  try {
    E e=getSession().lookup(entityClass,primaryKey);
    isRelationViaJoinTable=false;
    if (null != e) {
      logger.debug(entityClass.getName() + "String_Node_Str" + primaryKey+ "String_Node_Str");
      return e;
    }
    EntityMetadata entityMetadata=KunderaMetadataManager.getEntityMetadata(entityClass,getPersistenceUnits());
    Client client=getClient(entityMetadata);
    List<EntitySaveGraph> objectGraphs=getGraph(entityMetadata.getEntityClazz().newInstance(),entityMetadata);
    Map<Boolean,List<String>> relations=getRelations(objectGraphs,entityMetadata.getEntityClazz());
    EntityReader reader=getReader(client);
    List<String> relationNames=relations.values().iterator().next();
    String rowKey=primaryKey + "String_Node_Str";
    EnhanceEntity enhanceEntity=reader.findById(rowKey,entityMetadata,relationNames,client);
    Map<Object,Object> relationalValues=new HashMap<Object,Object>();
    E entity=(E)enhanceEntity.getEntity();
    if (relationNames.isEmpty() && !entityMetadata.isRelationViaJoinTable()) {
      return entity;
    }
 else {
      entity=(E)reader.computeGraph(enhanceEntity,objectGraphs,relationalValues,client,entityMetadata,this);
    }
    boolean isCacheableToL2=entityMetadata.isCacheable();
    getSession().store(primaryKey,entity,isCacheableToL2);
    return entity;
  }
 catch (  Exception exception) {
    exception.printStackTrace();
    throw new PersistenceException(exception);
  }
}